我在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);