I often find myself doing quick checks like this:
if (!eregi('.php', $fileName)) {
$filename .= '.php';
}
But as eregi()
was deprecated in PHP 5.3 the code now throws errors.
Is there another function that behaves exactly the same way as eregi()
? I don't know anything about regexps and don't want to learn, so preg_match()
etc won't work for me.
stristr achieves exactly the same result as eregi (at least when you don't use regular expressions):
if (!stristr($fileName, '.php'))
$filename.='.php';
You could also make a "fake" eregi this way:
if (!function_exists('eregi')) {
function eregi($find, $str) {
return stristr($str, $find);
}
}
Update: Note that stristr
doesn't accept regular expressions as eregi
does, and for this specific case (checking the extension), you'd better go with vartec's solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With