You are here

25 July 2013

Snippet about getting img tag image url from html using regex in PHP. Example below.

Source code viewer
  1. $html = '<img src="http://browse-tutorials.com/sites/browse-tutorials.com/themes/ram4nd/img/text.png" alt="written tutorial - SQL query examples in Drupal 7" style="float:left" width="16" height="16">
  2. <div class="created">20 Apr, 2012</div>
  3. <div class="body">Snippet about getting img tag image url from html using regex in PHP. Example below.</div>';
  4. if (preg_match('~<img.*?src=["\']+(.*?)["\']+~', $html, $matches)) {
  5. echo $matches[1];
  6. }
Programming Language: PHP