Jump to content


Photo

Manipulating a variable.


  • Please log in to reply
2 replies to this topic

#1 comeran

comeran
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 21 October 2006 - 12:00 AM

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-

#2 comeran

comeran
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 21 October 2006 - 12:20 AM

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.

#3 comeran

comeran
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 21 October 2006 - 01:06 AM

Ok I think that I have it but if anyone here thinks I am doing this all wrong I am open to suggestions :P

For others w/ the same problem you want to see the preg_replace function in the manual.
http://us3.php.net/m...reg-replace.php

I HAD
    $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.

THIS IS HOW I DID IT
    $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-




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users