php - extracting link from a string containing html and javascript -


i have string contains following:

<img data-bind="defaultsrc: {srcdesktop: 'http://desktoplink', srcmobile: 'http://mobilelink', fallback: 'http://baseurl'}" > 

i trying extract srcdesktop contained inside string. want final result yield me link http://desktoplink. best way achieve other str_replace? have dataset contains strings looking formula extract in php.

here how have been doing it, there got more efficient way:

$string = '<img data-bind="defaultsrc: {srcdesktop: \'http://desktoplink\', srcmobile: \'http://mobilelink\', fallback: \'http://baseurl\'}" >'; $test = explode(" ",$string); echo "<br>".str_replace(",","",str_replace("'","",$test['3'])); 

you can use preg_match

$string = '<img data-bind="defaultsrc: {srcdesktop: \'http://desktoplink\', srcmobile: \'http://mobilelink\', fallback: \'http://baseurl\'}" >';  preg_match('/.*\bsrcdesktop:\s*(?:\'|\")(.*?)(?:\'|\").*/i', $string, $matches);  if (isset($matches[1])) {     echo trim($matches[1]); } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -