obay Posted November 17, 2008 Share Posted November 17, 2008 for example, i want all <img src="someImage" width="someValue" height="someValue" /> to become <a> <img src="someImage" width="someValue" height="someValue" /> </a> i've tried: preg_replace('/<img[^>]+>/', '<a> $1 <a>', '<img src="" width="" height="" >'); but it doesn't work.. LOL sorry im really new to this thing any help? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 17, 2008 Share Posted November 17, 2008 Have a go at this one: $str = '<img src="someImage" width="someValue" height="someValue" />'; $newStr = preg_replace("#(<img[^.]+>)#", "<a>\\1</a>", $str); echo htmlentities($newStr); Quote Link to comment Share on other sites More sharing options...
obay Posted November 17, 2008 Author Share Posted November 17, 2008 wow thanks!! how do i make this work for when there is more than one <img> in $str? for example, if $str is <img /> <img /> it yields <a><img /> <img /></a> instead of <a><img /></a> <a><img /></a> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.