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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.