Forum Moderators: coopster
Q: i have html string that comes from a html file. it has lots of tags and text but.what i wand to do is to change the image tags and their link to my own images and links. for example:
find images and their links like
<a ... href="someURL.jpg"...><img ... src="thumb_URL.jpg"></a>
<a ... href="someURL.jpg"...>SOME TEXT</a>
give me the Link URL and Thumb URL , and iwill do some actions on them and replace the orginals including all parameters :
<a alt="my alt" href="my_Url.jpg"><img alt="my_alt" src="my_thumb.jpg"></a>
<a alt="my alt" href="my_Url.jpg">My Text</a>
i know something about preg_replace but not professional and any pattern i made, not worked :(. i just could extract the URLs and do my changes on them but i couldn't replace them with perevious tags in orginal file.
any help would be appreciated.
thanks for any help.
preg_match_all('/<a[\s]+[^>]*href\s*=\s*[\"\']?([^\'\" >]+)[\'\" >]/i',$html,$out,PREG_PATTERN_ORDER) ;
but for replacement i tried below codes but they did not work:
$myhtml = Preg_replace('¦<a[^>].*[^>]'. preg_quote($old_url) .'[^>].*>¦U','<a href="my_URL" alt="$title" >',$html);
$myhtml = Preg_replace('/<a[\s]+[^>]*href\s*=\s*[\"\']?' . $Old_URL . '[\'\" >]/i',$html) ;