您好我正在使用WordPress,我想替换以下
$items = array( ".","?","!",",","؟","،",":","™","*" );
所以我编写了这个功能
function Huemix_content_filter_chars($content){
$items = array();
$items = array( ".","?","!",",","؟","،",":","™","*" );
$before='<span class="kindared">';
$after='</span>';
foreach ( $items as $k => $val ) {
$content = preg_replace("|(\\$val)|","$before$1$after",$content);
$content = preg_replace("|(<[^>]+?)($before(\\$val)$after)([^<]+?>)|","$1$3$4",$content);
}
return $content;
}
add_filter('the_content', 'Huemix_content_filter_chars');
我不明白什么是错的! 它工作,但不完全 它打破了这个链接
<a href="http://facebook.com/huemix.ly">Huemix Studio, Inc™</a>
它打印得像这样
<a href="http<span class=" kindared"="">://facebook<span class="kindared">.</span>com/huemix<span class="kindared">.</span>ly">Huemix Studio<span class="kindared">,</span> Inc<span class="kindared">™</span></a>
但它没有打破第二个链接
Follow Us On Facebook <a href="http://facebook.com/huemix.ly">Huemix Studio, Inc™</a>
Follow Us On Twitter <a href="http://twitter.com/HuemixStudio">Huemix Studio, Inc™</a>
你可以在网上看到我的问题
它正在制作我的帖子图片,这里是我的html帖子图片的输出
<div class="huemix-works "><img class='huemix-works-image' alt='Huemix Studio Works' src='http://alpha.huemix.ly/wp-content/uploads/Huemix_temp/NASER-GROUP1-698998_140x94.png' /><span class='huemix-works-overlay'></span><a class="huemix-works-zoom-icon huemix-fancybox" title="Huemix Studio Works" href="http://alpha.huemix.ly/wp-content/uploads/2013/11/NASER-GROUP1.png" rel="media">Zoom In</a></div>
答案 0 :(得分:0)
为什么不直接使用str_replace?
$items = array( ".","?","!",",","؟","،",":","™","*" );
$content = str_replace($items, '', $content);