Good alternative to eregi() in PHP

前端 未结 8 1577
感情败类
感情败类 2021-01-04 08:39

I often find myself doing quick checks like this:

if (!eregi(\'.php\', $fileName)) {
    $filename .= \'.php\';
}

But as eregi() was deprec

8条回答
  •  执笔经年
    2021-01-04 09:07

    Perhaps you should consider refactoring your code to do this instead:

    if (substr($fileName, -4, 4) !== '.php')
        $fileName .= '.php';
    

    As stated in other answers to this question, eregi('.php') will search for anything followed by 'php' ANYWERE in the file (not just at the end).

提交回复
热议问题