【发布时间】:2017-01-21 14:31:29
【问题描述】:
我正在尝试在内容中的任何链接的末尾添加一个字符串,我正在尝试以下代码:
add_filter('the_content', 'crawl_content');
function crawl_content( $text ) {
$search = '/href="(.*?)"/s';
preg_match_all( $search, $text, $matches);
for ($a = 0; $a < count($matches[0]); $a++) {
$new = "href=\"" . $matches[1][$a] . "/?=dddd\" class=\"newsLink\"";
$text = preg_replace('%' . $matches[0][$a] . '%', $new, $text);
}
return $text;
}
问题是:
Warning: preg_replace(): Unknown modifier 'd' in functions.php on line 112
【问题讨论】:
-
欢迎来到 SO!如果你需要帮助,你需要更清楚一点。什么文本被传递到您的过滤器?返回什么文本?您希望返回的文本如何不同(或者,如果它是“正确的”会是什么?具体。细节很重要!
-
@cale_b 我编辑我的帖子
-
$text的内容是什么?112是哪一行? -
你不够具体。您传递给函数的文本是什么?你想添加什么?在哪里?你代码的哪一行是 112?
标签: php wordpress preg-replace preg-match-all