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? Link to comment https://forums.phpfreaks.com/topic/133019-solved-how-do-i-wrap-and-around-an-using-regular-expressions/ 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); Link to comment https://forums.phpfreaks.com/topic/133019-solved-how-do-i-wrap-and-around-an-using-regular-expressions/#findComment-691829 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> Link to comment https://forums.phpfreaks.com/topic/133019-solved-how-do-i-wrap-and-around-an-using-regular-expressions/#findComment-691833 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.