fraser5002 Posted November 14, 2010 Share Posted November 14, 2010 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 More sharing options...
tomtimms Posted November 15, 2010 Share Posted November 15, 2010 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; Link to comment https://forums.phpfreaks.com/topic/218675-help-with-php-string/#findComment-1134220 Share on other sites More sharing options...
spfoonnewb Posted November 15, 2010 Share Posted November 15, 2010 Should absolutely use regex to solve this. Link to comment https://forums.phpfreaks.com/topic/218675-help-with-php-string/#findComment-1134221 Share on other sites More sharing options...
chintansshah Posted November 15, 2010 Share Posted November 15, 2010 Use explode for fetch data. But not with "=" sign because you may get = sign in query string of url. better todo with "src=" Link to comment https://forums.phpfreaks.com/topic/218675-help-with-php-string/#findComment-1134307 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.