comeran Posted October 21, 2006 Share Posted October 21, 2006 I have a variable that comes out with a full HTML img tag.I need to remove all the text before the img name, and all the text after so the only thing left is the actual name of the image.EXAMPLE: <img src="%%URLofImages%%/WHATINEED.JPG" style="border: 0px">so I need to remove the "<img src="%%URLofImages%%/" and the "" style="border: 0px">" from the string to leave WHATINEED.JPG.I have looked up variable manipulation, variable editing, variable text stripping and have found nothing that fits what I am looking to do.Thanks for all the help.Com- Quote Link to comment Share on other sites More sharing options...
comeran Posted October 21, 2006 Author Share Posted October 21, 2006 After reading this post I noticed that I might not have been too clear on what I am tring to do ::)Right now I have: $variable = <img src="%%URLofImages%%/WHATINEED.JPG" style="border: 0px">;and I need it to be: $variable = WHATINEED.JPG;-----------------I could have done this in PERL using $variable = <img src="%%URLofImages%%/WHATINEED.JPG" style="border: 0px">; $variable =~ s/<img src=\"%%URLofImages%%\///g; $variable =~ s/\" style=\"border: 0px\">//g;I just can't figure out how it's done in PHP.Thanks again for the help. Quote Link to comment Share on other sites More sharing options...
comeran Posted October 21, 2006 Author Share Posted October 21, 2006 Ok I think that I have it but if anyone here thinks I am doing this all wrong I am open to suggestions :pFor others w/ the same problem you want to see the preg_replace function in the manual.[url=http://us3.php.net/manual/en/function.preg-replace.php]http://us3.php.net/manual/en/function.preg-replace.php[/url][b]I HAD[/b] $imagename = $data['image'];which came out like: $imagename = <img src="%%URLofImages%%/WHATINEED.JPG" style="border: 0px">;and all I wanted was "WHATINEED.JPG" so I needed to remove text before and after that text.[b]THIS IS HOW I DID IT[/b] $imagetemp = $data['image']; $patterns[0] = '/<img src=\"%%URLofImages%%\//'; $patterns[1] = '/\" style=\"border: 0px\">/'; $replacements[1] = ''; $replacements[0] = ''; $imagename = preg_replace($patterns, $replacements, $imagetemp);There could be a better way, and if anyone here knows then please feel free I just wanted to post the answer that I had in case it would help others in my spot.Thanks for the great board, I will be using this often on my journal to learn PHP.Com- 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.