我正在學習一些預製網站的PHP,所以我可以看到它是如何完成的,因爲我是一個視覺學習者,但我遇到了問題。preg_replace_callback():需要參數2是有效的回調
我得到了一個錯誤說
preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead
現在我知道這是因爲不支持preg_replace()
但preg_replace_callback()
,但在改變它一個較新的PHP的,我得到這個錯誤:
preg_replace_callback(): Requires argument 2, 'preg_replace('/(.{59})/', '\$1< >', '$1')', to be a valid callback
該代碼在聊天室中留下了太長的消息,分成兩個單獨的聊天室,以保留聊天窗口中的所有字母。
錯誤位於第20行,其中只有$msg);
的立場。
if ($shoutbox['fixLongWords'] > 5 && $shoutbox['fixLongWords'] < $shoutbox['maxMsgLenght'])
{
$non_breaking_space = $context['utf8'] ? ($context['server']['complex_preg_chars'] ? '\x{A0}' : "\xC2\xA0") : '\xA0';
if ($context['browser']['is_gecko'] || $context['browser']['is_konqueror'])
$breaker = '<span style="margin:0 -0.5ex 0 0"> </span>';
elseif ($context['browser']['is_opera'])
$breaker = '<span style="margin:0 -0.65ex 0 -1px"> </span>';
else
$breaker = '<span style="width:0;margin:0 -0.6ex 0 -1px"> </span>';
$shoutbox['fixLongWords'] = (int) min(1024, $shoutbox['fixLongWords']);
if (strlen($msg) > $shoutbox['fixLongWords'])
{
$msg = strtr($msg, array($breaker => '< >', ' ' => $context['utf8'] ? "\xC2\xA0" : "\xA0"));
$msg = preg_replace(
'~(?<=[>;:!? ' . $non_breaking_space . '\]()]|^)([\w\.]{' . $shoutbox['fixLongWords'] . ',})~e' . ($context['utf8'] ? 'u' : ''),
'preg_replace(\'/(.{' . ($shoutbox['fixLongWords'] - 1) . '})/' . ($context['utf8'] ? 'u' : '') . '\', \'\\$1< >\', \'$1\')',
$msg);
$msg = strtr($msg, array('< >' => $breaker, $context['utf8'] ? "\xC2\xA0" : "\xA0" => ' '));
}
}
任何人都知道什麼可能會導致問題?
「preg_replace_callback()」的第二個參數是一個匿名函數,例如, 'function(){...}'或函數名稱,例如''functionNameAsString「',然後你可以像我看到的一個普通函數 – Rizier123