我想在链接文字之前添加图标。例如,我有以下链接:
<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>
我想在链接文字之前添加Icon:
<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 :(得分:3)
替换起始标记的结尾。
preg_replace('#(<a [^>]*>)#', '$1<i class="icon" />', $source);