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. Quote Link to comment 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); ?> Quote Link to comment 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 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.