Php 将preg_replace转换为preg_replace_回调

Php 将preg_replace转换为preg_replace_回调,php,Php,我需要帮助将preg_replace转换为preg_replace_回调 PHP 5.4及以上版本触发以下语句: 不推荐使用/e修饰符,请在中使用preg\u replace\u回调 我尝试过改变: if (stripos ( $tpl->copy_template, "[category=" ) !== false) { $tpl->copy_template = preg_replace ( "#\\[category=(.+?)\\](.*?)\[/category\\

我需要帮助将preg_replace转换为preg_replace_回调

PHP 5.4及以上版本触发以下语句:
不推荐使用/e修饰符,请在中使用preg\u replace\u回调

我尝试过改变:

if (stripos ( $tpl->copy_template, "[category=" ) !== false) {
    $tpl->copy_template = preg_replace ( "#\\[category=(.+?)\\](.*?)\[/category\\]#ies",         "check_category('\\1', '\\2', '{$category_id}')", $tpl->copy_template );
}


返回值为空

因为
$category\u id
是一个全局变量,所以必须在带有
全局
关键字的函数中使用它。数字数组的键是整数而不是字符串;因此,您必须编写
$cat[1]
而不是
$cat['1']
$cat[2]
而不是
$cat['2']

通过这些小改动,您的功能将变为:

function($cat){
        global $category_id;
        return check_category($cat[1], $cat[2], $category_id);
}

检查类别做什么?检查类别。。。它相当大,所以我决定不包括它<代码>功能检查\类别($cats,$block,$category,$action=true){..}
function($cat){
        global $category_id;
        return check_category($cat[1], $cat[2], $category_id);
}