Jump to content

help with php string


fraser5002

Recommended Posts

Hi i have a php string in the form of an html tag i.e

 

my php string

 

$string = "<img title="http://www.mydomain.com/pic.jpg" src="http://www.mydomain.com/pic.jpg" alt="http://www.mydomain.com/pic.jpg" width="400" height="300" />

 

how do i extract out the src part of the tag so that i am just left with $src = "http://www.mydomain.com/pic.jpg"

 

Many thanks

Link to comment
https://forums.phpfreaks.com/topic/218675-help-with-php-string/
Share on other sites

Didn't put much thought on this, but I would explode the string by the "=" sign, then do some trimming.

 

$url = "<img title='http://www.mydomain.com/pic.jpg' src='http://www.mydomain.com/pic.jpg' alt='http://www.mydomain.com/pic.jpg' width='400' height='300' />";

 

$a = explode('=',$url);

$b = $a[1];

 

$trim = trim($b,"'");

$trim_b = trim($trim,"' src");

echo $trim_b;

Archived

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

×
×
  • Create New...

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.