nrg_alpha Posted August 26, 2008 Share Posted August 26, 2008 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 https://forums.phpfreaks.com/topic/121121-solved-detecting-if-a-string-ends-with-another/page/2/#findComment-626416 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.