Jump to content

Preg_match() ahhhhhhhhhhhhh


TEENFRONT

Recommended Posts

Hey

 

im usuing preg_match() to try match a search term to a file title in a directory.

 

Now i have the directory listing script working fine, it basically lists all files in a directory, simple.

 

But i tried making it only list files matching a search term.

 

// $filetitle is something like 'Transformers'
// $search is 'Transformers'

if(preg_match('/$search/', $filetitle)) {

echo "$filetitle Contains '$search'<br />";  // success!
}
else { 
echo "$filetitle - Doesn't contain '$search' <br />"; // Doesnt match, not good.
}

 

as a test im getting it to loop through all the files in the directory and say if it containts the search term or not.

 

All i get in the output is

 

Transformers - Doesn't contain 'Transformers'

otherfilm  - Doesn't contain 'Transformers'

otherfilm  - Doesn't contain 'Transformers'

etc etc

 

Actually...i may have just figured out my issue... preg_match uses $ as an end sign for the search right..so basically its matching nothing...hmm.. in that case, new questions...

 

Whats the best way to search the file names and try matching them to a search term as if i cannot use a variable in preg_match...?

Link to comment
https://forums.phpfreaks.com/topic/123134-preg_match-ahhhhhhhhhhhhh/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.