Jump to content

[SOLVED] Detecting if a string ends with another


jordanwb

Recommended Posts

So it would be like this:

 


if (preg_match('#Theme\.php$#', $file))
{
include ($file);
}

 

Yep, that should do it. If you want the match to be case insensative, you can simply add the i modifier after the last delimiter like so:

 

if (preg_match('#Theme\.php$#i', $file))

 

That way, whether the file is Theme.php or theme.php or THEME.PHP.. it won't matter.

Lastly, incase you are wondering about the escaped period (\.) instead of just a period is because the period acts as a wild card (it means any character..(althought in reality I don't think it includes newlines)). So if you had:

 

if (preg_match('#Theme.php$#i', $file))

 

The unescaped period acts as a wildcard and as a result can match stuff like: Theme_php, Theme-php, Theme*php, Themexphp, etc.. so by escaping the period with a backslash, that wildcard metacharacter looses its meaning and simply becomes a period (thus, only theme.php can be matched).

 

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.