Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
urgent help - 'spider' file
Old 05-10-2009, 03:03 PM urgent help - 'spider' file
Average Talker

Posts: 26
Trades: 0
I was working on my program the other day, and I decided to add in a function to create database and tables, but since then it is telling me that line 64 being the '$pattern = (\.php)' section has an error...but this was fine before

If anyone could take a look at my code and see if they can spot anything as to why would be greatly appreciated

Code:
 
<?php

$dbh = mysql_connect("localhost", "root", "")
  OR die("Unable to connect to MySQL");
print "Connected to MYSQL<br>";

// create database
if (mysql_query("CREATE DATABASE websearcher", $dbh))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: ";
  }
// create tables
$selected = mysql_select_db("websearcher", $dbh)
 or die("Could not select websearcher");
$sql_table1 = "CREATE TABLE header
(
headerId integer not null auto_increment,
fileName varchar(255) not null,
primary key headerId
)";
if(mysql_query($sql_table1, $dbh))
{
 print "table 1 created  <p>";
}

$sql_table2 = "CREATE TABLE vals
(
headerFk integer not null,
word varchar(255) not null,
primary key (headerFk, word)
)";
if(mysql_query($sql_table2,$dbh))
{
 print "table 2 created  <p>";
}

function opening($file)
{
$stoplist = "F:/xampplite/htdocs/worksheets/stoplist.txt"
$pattern = "(\.txt$)| (\.php$)";
if(eregi($pattern, $file)){
 $file_handle = fopen($file, "r");
 $contents = file($file);
 if(sizeof($contents)>0)
 {
  $query_header="INSERT INTO HEADER (filename) values ('$file')";
  mysql_query($query_header);
     //get back header id value
  $headerId=mysql_insert_id();
 }
 while (!feof($file_handle)){
  $data = fgets($file_handle);
  $words = explode(' ' , $data);
  $duplicates = array_unique($words);
  sort($duplicates);
  if(is_bool(strpos($stoplist, " $duplicates[i] "))
  foreach($duplicates as $word)
  {
   $word = serialize($word);
   $sql = "INSERT INTO vals (headerFk, word) VALUES($headerId, '$word')";
   if (mysql_query($sql))
   {
    print "successful <p>";
   }
  }
}
}
else {
echo "Cant open that file type <p>"; }
}
 
function getfiles($dirname=".")
{
$pattern = "(\.txt$)| (\.php$)| (\.html)| (\.html)";
$file = array($file);
if($handle = opendir($dirname)) {
 while(false !== ($file = readdir($handle))){
  if(eregi($pattern, $file) || is_dir($file))
  echo "$file <br />";
  opening($file);
 
}
closedir($handle);
}
return($file);
}

getfiles("F:/xampplite/htdocs/worksheets");
 

mysql_close($dbh);
?>
applebiz89 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-11-2009, 09:59 AM Re: urgent help - 'spider' file
nayes84's Avatar
Extreme Talker

Latest Blog Post:
Difference between ASP And JSP
Posts: 232
Name: John
Location: Tokyo
Trades: 0
there are two lines having that pattern you mentioned. wonder which one you are having the problem with. or if you are having the problem with both.

but I just have some note concerning the second one
PHP Code:
$pattern "(\.txt$)| (\.php$)| (\.html)| (\.html)"
wonder what is the point you write \.html two times. also wonder why there is no $ sign in the end of .\html while there is one with both txt and php patterns.
may be fixing these things would fix the problem or at least clear up the problem

btw. patterns may work with some php series and doesn't work with the other one. you should also make sure your hosting didn't change php version or something.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

if(I'm("Helpful")) Add_Talkupation("nayes84");

Last edited by nayes84; 05-11-2009 at 10:01 AM..
nayes84 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to urgent help - 'spider' file
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11544 seconds with 12 queries