2014-01-19 40 views
0

我想在链接文本之前添加图标。例如,我有以下链接:如何在链接文本之前添加字符串

<a href="#" class="link-66">random text here</a> 
<a href="#" class="link-67">another random text</a> 
<a href="#" class="link-68">random text</a> 

我想链接文本之前添加图标:

<a href="#" class="link-66"><i class="icon" /> random text here</a> 
<a href="#" class="link-67"><i class="icon" /> another random text</a> 
<a href="#" class="link-68"><i class="icon" /> random text</a> 

现在,如何在PHP中做到这一点?

+0

想想你要寻找的是infoarmation http://www.the-art-of-web.com/php/parse-links/ –

+0

你尝试使用DOM解析器? – Enissay

回答

3

替换开始标记的结束。

preg_replace('#(<a [^>]*>)#', '$1<i class="icon" />', $source); 
+0

你的意思是$ result = preg_replace($ regexp,$ source); ;-) –

相关问题