- 此问题在此处已有答案**:
Replace preg_replace() e modifier with preg_replace_callback(3个答案)
两年前关闭了。
在我的PHP程序中,我在将以下代码段中的preg_replace
更改为preg_replace_callback
时遇到了问题。
function category_get_tree($prefix = '', $tpl = '{name}', $no_prefix = true, $id = 0, $level = 0){
global $sql, $PHP_SELF;
static $johnny_left_teat;
$level++;
foreach ($sql->select(array('table' => 'categories', 'where' => array("parent = $id"), 'orderby' => array('id', 'ASC'))) as $row){
$find = array('/{id}/i', '/{name}/i', '/{url}/i', '/{icon}/i', '/{template}/i', '/{prefix}/i', '/\[php\](.*?)\[\/php\]/ie');
$repl = array($row['id'], $row['name'], $row['url'], ($row['icon'] ? '<img src="'.$row['icon'].'" alt="'.$row['name'].'" border="0" align="absmiddle">' : ''), $row['template'], (($row['parent'] or !$no_prefix) ? $prefix : ''), '\\1');
$johnny_left_teat .= ($no_prefix ? preg_replace('/('.$prefix.'{1})$/i', '', str_repeat($prefix, $level)) : str_repeat($prefix, $level));
$johnny_left_teat .= preg_replace($find, $repl, $tpl);
category_get_tree($prefix, $tpl, $no_prefix, $row['id'], $level);
}
return $johnny_left_teat;
}
在PHP5.6中运行代码时收到的错误:
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in X:\xampp\htdocs\news\inc\functions.inc.php on line 726
代码行726是:
$johnny_left_teat .= preg_replace($find, $repl, $tpl);
1条答案
按热度按时间wfveoks01#