daveofwar Posted October 28, 2007 Share Posted October 28, 2007 Does anyone know how to get the content of src in the html tag img. For example <img src="http://path.to/img" id="randomid" /> In the example the string i would like to get would be http://path.to/img Thanks Quote Link to comment Share on other sites More sharing options...
toplay Posted October 29, 2007 Share Posted October 29, 2007 There's probably a better way to do it, but this is off the top of my head for now: <?php $html = '<img src="http://path.to/img" id="randomid" />'; if (preg_match('/<img.+?src(?: )*=(?: )*[\'"](.*?)[\'"]/si', $html, $arrResult)) { echo $arrResult[1]; // Should display http://path.to/img } else { echo "No match found"; } ?> Quote Link to comment Share on other sites More sharing options...
effigy Posted October 29, 2007 Share Posted October 29, 2007 /<img[^>]+src=([\'"])?((?(1).+?|[^\s>]+))(?(1)\1)/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.