Jump to content

Archived

This topic is now archived and is closed to further replies.

comeran

Manipulating a variable.

Recommended Posts

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-

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.
[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-

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.