slough Posted April 23, 2008 Share Posted April 23, 2008 I have this HTML-code: <img id="ff_header" src="/files/imce_images/image_file.jpg" height="400" width="400" /> ...and want to replace it with this: <a href="/url/to/page"><img id="ff_header" src="/files/imce_images/image_file.jpg" height="400" width="400" /></a> Should I use preg_replace()? How do I solve this? Cheers! Link to comment https://forums.phpfreaks.com/topic/102482-prepend-and-append-html-code-on-img-tag/ Share on other sites More sharing options...
aCa Posted April 23, 2008 Share Posted April 23, 2008 You could use somthing like this: preg_replace('/(<img[^>]+>)/i', '<a href="/url/to/page">$1</a>', '<img id="ff_header" src="/files/imce_images/image_file.jpg" height="400" width="400" />'); Link to comment https://forums.phpfreaks.com/topic/102482-prepend-and-append-html-code-on-img-tag/#findComment-524753 Share on other sites More sharing options...
slough Posted April 23, 2008 Author Share Posted April 23, 2008 Problem solved. Thanks! Link to comment https://forums.phpfreaks.com/topic/102482-prepend-and-append-html-code-on-img-tag/#findComment-524806 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.