preg_replace_callback返回一个空字符串?

时间:2017-04-18 01:09:14

标签: php

我有一个WordPress插件(对于它的部分功能),可以在帖子中运行php并将输出放在屏幕上的适当位置。守则如下:

add_filter('the_content', 'twomb_autocode_do_php', 0); //Parse php in the post with [php] ... [/php] tags.
function twomb_autocode_do_php($content) {
    $content = preg_replace_callback('/\[php\]((.|\n)+)\[\/php\]/', 'twomb_autocode_exec_php', $content); //I know, weird regex.
    return $content;
}

function twomb_autocode_exec_php($matches) {
    ob_start();
    eval($matches[1]);
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}

但是,当帖子中有[php]echo "hi!";[/php]之类的简单内容时,返回的内容为“”(空)。如果没有包含php标签,内容显示正常(虽然显然没有php)。我已经到处寻找preg_replace_callback返回一个空字符串的地方,我发现远程关闭的唯一一件事是php上的一个虚假错误,无效的unicode字符导致preg_replace_callback返回一个空字符串虽然我几乎可以肯定我的字符串根本没有任何unicode字符。

- 迈克尔。

P.S。抱歉格式化 - 我的屏幕阅读器与本网站上的编辑器完全不兼容。

0 个答案:

没有答案
相关问题