2014-01-19 78 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); ;-) –

相關問題