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
pattern matching - problem
Old 06-24-2009, 04:04 AM pattern matching - problem
Average Talker

Posts: 26
Trades: 0
I have come across a new problem with my program, in which the pattern I have provided it only opens and read's .txt files I assume this is because this is the first on the list.

PHP Code:
function opening($file)
{

$pattern "(\.txt$)| (\.php$)| (\.html$)| (\.htm$)"// pattern to match
if(eregi($pattern$file)){
 
$file_handle fopen($file"r");
 
$contents file($file);
 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 webdata VALUES('$file','$word')";
   if (
mysql_query($sql))
   {
    print 
"successful <p>";
   }
  }
  }

}
}
else {
echo 
"Cant open that file type <p>"; }

How can I fix this so it opens all the provided file extensions?
applebiz89 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-24-2009, 11:40 AM Re: pattern matching - problem
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
I usually use something like this (just easier from my perspective, so no other reason why):
PHP Code:
$allowed_extensions = array('txt'=>true
                            
'php'=>true,
                            
'htm'=>true,
                            
'html'=>true);
$path_parts pathinfo($file);
if(isset(
$allowed_extensions[$path_parts['extension']])){ 
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 06-24-2009, 12:02 PM Re: pattern matching - problem
Average Talker

Posts: 28
Name: Fred Van Andel
Trades: 0
You have spaces in your regex. it is looking for files that end in " .php" rather than ".php"

Remove the spaces and it should work
__________________

Please login or register to view this content. Registration is FREE
tracks and graphs host reviews.
fava is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to pattern matching - problem
 

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.47311 seconds with 12 queries