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).

 

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.