$pattern = '/<a href="?(.*:\/\/)?([^ \/]*)([^ >"]*)"?[^>]>(.*)(<\/a>)/ig';
colm_c wrote: It doesn't seem to work with more than 1 link in the text. Did you try it with a couple of links?
<?PHP $content = <<<END <ul> <li><a href="http://us.ard.yahoo.com/SIG=12lgn363s/M=385895.10615157.11509033.7674020/D=yahoo_top/S=2716149:FPAD/_ylt=AjIVmKHx06EPO2i9ahEcDdf1cSkA/Y=YAHOO/EXP=1182346617/A=4545677/R=8/SIG=14ufch571/*http://shopping.yahoo.com/b:Diamond%20Buying%20Guide:784708673;_ylc=X3oDMTFsY2kzZGxyBF9TAzI3MTYxNDkEc2VjA2ZwLWhtYW50bGUEc2xrA2ZpbGxlcmFkLWFwcmlsLWRpYW1vbmRz">Diamond</a></li> <li><a href="http://us.ard.yahoo.com/SIG=12lgn363s/M=385895.10615157.11509033.7674020/D=yahoo_top/S=2716149:FPAD/_ylt=AjIVmKHx06EPO2i9ahEcDdf1cSkA/Y=YAHOO/EXP=1182346617/A=4545677/R=9/SIG=14ukb9290/*http://shopping.yahoo.com/b:Jewelry%20Buying%20Guide:784708697;_ylc=X3oDMTFrOGdrMjlpBF9TAzI3MTYxNDkEc2VjA2ZwLWhtYW50bGUEc2xrA2ZpbGxlcmFkLWFwcmlsLWpld2Vscnk-">Jewelry</a></li> <li><a href="http://us.ard.yahoo.com/SIG=12lgn363s/M=385895.10615157.11509033.7674020/D=yahoo_top/S=2716149:FPAD/_ylt=AjIVmKHx06EPO2i9ahEcDdf1cSkA/Y=YAHOO/EXP=1182346617/A=4545677/R=10/SIG=15544heiq/*http://shopping.yahoo.com/b:Engagement%20Buying%20Guide:784708681;_ylc=X3oDMTFua2tyYW82BF9TAzI3MTYxNDkEc2VjA2ZwLWhtYW50bGUEc2xrA2ZpbGxlcmFkLWFwcmlsLWVuZ2FnZW1lbnQ-">Engagement</a></li> </ul> END; $pattern = '/<a href="?(.*:\/\/)?([^ \/]*)([^ >"]*)"?[^>]>(.*)(<\/a>)/'; $replacement = '<a href="$1$2$3">$4 <img src="/images/icon_web.gif" alt="external link" /></a>'; $content = preg_replace($pattern, $replacement, $content, -1); print $content; ?>
a[href $='.pdf'] { padding-right: 18px; background: transparent url(icon_pdf.gif) no-repeat center right; }