当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Moxiecode ereg replacement not finding search results

问题描述:

As im running php7 on my new server i have an issue with the moxiecode filemanager as it uses ereg.

In the code that causes the search to error out i have this :

function _fnmatch($pattern, $file) {

return ereg($this->_fnmatch2regexp(strtolower($pattern)), strtolower($file));

}

function _fnmatch2regexp($str) {

$s = "";

for ($i = 0; $i<strlen($str); $i++) {

$c = $str{$i};

if ($c =='?')

$s .= '.'; // any character

else if ($c == '*')

$s .= '.*'; // 0 or more any characters

else if ($c == '[' || $c == ']')

$s .= $c; // one of characters within []

else

$s .= '\\' . $c;

}

$s = '^' . $s . '$';

//trim redundant ^ or $

//eg ^.*\.txt$ matches exactly the same as \.txt$

if (substr($s,0,3) == "^.*")

$s = substr($s, 3);

if (substr($s,-3,3) == ".*$")

$s = substr($s, 0, -3);

return $s;

}

the ereg i have changed to preg_match like :

preg_match('/^'.$this->_fnmatch2regexp(strtolower($pattern)).'/', strtolower($file));

The error is gone however no results are returned either. What do i miss in the preg_match for this to work the same as the ereg in the original code?

分享给朋友:
您可能感兴趣的文章:
随机阅读: