3
我曾经有这个代码块来模拟某种的BBCode的弃用:preg_replace函数的/ e修饰符使用数组作为图案和替换
$pattern = array(
'/\\n/',
'/\\r/',
'/\[list\](.*?)\[\/list\]/ise',
'/\[b\](.*?)\[\/b\]/is',
'/\[strong\](.*?)\[\/strong\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[s\](.*?)\[\/s\]/is',
'/\[del\](.*?)\[\/del\]/is',
'/\[url=(.*?)\](.*?)\[\/url\]/ise',
'/\[email=(.*?)\](.*?)\[\/email\]/is',
'/\[img](.*?)\[\/img\]/ise',
'/\[color=(.*?)\](.*?)\[\/color\]/is',
'/\[font=(.*?)\](.*?)\[\/font\]/ise',
'/\[bg=(.*?)\](.*?)\[\/bg\]/ise',
'/\[size=(.*?)\](.*?)\[\/size\]/ise'
);
$replace = array(
'<br/>',
'',
'$this->sList(\'\\1\')',
'<b>\1</b>',
'<strong>\1</strong>',
'<i>\1</i>',
'<span style="text-decoration: underline;">\1</span>',
'<span style="text-decoration: line-through;">\1</span>',
'<span style="text-decoration: line-through;">\1</span>',
'$this->urlfix(\'\\1\',\'\\2\')',
'<a href="mailto:\1" title="\1">\2</a>',
'$this->imagefix(\'\\1\')',
'<span style="color: \1;">\2</span>',
'$this->fontfix(\'\\1\',\'\\2\')',
'$this->bgfix(\'\\1\',\'\\2\')',
'$this->sizefix(\'\\1\',\'\\2\')'
);
return preg_replace($pattern, $replace, nl2br(stripslashes($string)));
但我移动到PHP 5.5,我收到错误在这里,它曾经很好地工作,这是错误回报我得到:
推荐使用:的preg_replace():本/ e修饰符已过时,使用 preg_replace_callback相反在
我尝试了几个东西,但迄今没有任何工作。
这是我试过到目前为止代码:
return preg_replace_callback(
$pattern,
function($matches) use ($replace) {
return ((isset($replace[$matches[0]])) ? $replace[$matches[0]] : '');
},
nl2br(stripslashes($string))
);
我一直在读左右,但大多数的例子都涉及到基本替换,在这里我有两个数组。
请通知有一些方法正在从$ replace区域中调用。
我该如何解决这个问题?这是正确的方法吗?
转到http://stackoverflow.com/questions/21334934/deprecated-preg-replace-the-e-modifier-is-deprecated-use-preg-replace-call链接 – WisdmLabs
我有点麻烦理解你试图做什么。是否你试图在'use'部分传递两个数组? – Quixrick
不,它只是一个数组。我只是期待着和以前一样的结果。 – Lucas