【发布时间】:2014-08-24 11:43:09
【问题描述】:
我使用的 Google 字体 (Amatic SC) 在他的粗体版本中显示 ® 符号而不是问号。
为了解决这个问题,我想使用 preg_replace,在我的 $content h1-h6 内搜索任何类型的问号 (?,¿)标签(我只在标题中使用这种字体)并将它们包装在一个额外的 span 元素中以分配它们不同的类,以便我可以使用普通版本而不是字体的粗体版本。
由于我对正则表达式不太熟悉,因此我很难做到这一点。我不知道如何只搜索问号并将它们包装在一个额外的跨度内。
function.php 中的当前 Wordpress 代码:
function replace_content($content){
$regex = '#(<h([1-6])[^>]*>)\s?(.*)?\s?(<\/h\2>)#';
$content = preg_replace($regex,'\1<span class="normal">\3</span>\4',$content);
return $content;
}
add_filter('the_content','replace_content');
函数应该替换类似这样的标记:
<h1>¿This is a questions?</h1>
用这个:
<h1><span class="normal">¿</span>This is a questions<span class="normal">?</span></h1>
【问题讨论】:
标签: php regex wordpress preg-replace