t_machine Posted December 5, 2008 Share Posted December 5, 2008 Hi, I am wondering if anyone could help with this. I have a string that has both text and images but i would like to remove the first image only. Example: $string = 'This is my test <img src="link_to_image1" border="0">, some other text.<img src="link_to_another_image" border="0">'; How can I use preg_replace to remove <img src="link_to_image1" border="0"> Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/135731-solved-how-to-preg_replace-first-image-from-string/ Share on other sites More sharing options...
Caesar Posted December 6, 2008 Share Posted December 6, 2008 <?php $string = 'This is my test <img src="link_to_image1" border="0">, some other text.<img src="link_to_another_image" border="0">'; $str = preg_replace('/\<img src=\"[aA-zZ0-9\/\_\.]+\" border=\"[0-9]+\"\>/','',$string, 1); ?> Link to comment https://forums.phpfreaks.com/topic/135731-solved-how-to-preg_replace-first-image-from-string/#findComment-707257 Share on other sites More sharing options...
t_machine Posted December 6, 2008 Author Share Posted December 6, 2008 Thank you very much. Works great Link to comment https://forums.phpfreaks.com/topic/135731-solved-how-to-preg_replace-first-image-from-string/#findComment-707277 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.