Grab SRC from IMG tag


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. $str = '<h2> this is a test</h2><img src="pathrourl.jpg" alt="test" />';
  2. $find = '/<img.*src="(.*?)"/';
  3. $match = preg_match($find, $str, $img );
  4. if ( $match )
  5. echo $img[1];

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.