Skip to content

Instantly share code, notes, and snippets.

@jswebschmiede
Forked from vyspiansky/image-src-regexpr.php
Created March 23, 2023 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jswebschmiede/9e2b8ae6fe046e3bce0b4a9c90577534 to your computer and use it in GitHub Desktop.
Save jswebschmiede/9e2b8ae6fe046e3bce0b4a9c90577534 to your computer and use it in GitHub Desktop.
PHP: get image src attribute (regular expression)
<?php
// Source: http://goo.gl/qyLFbg
$html = '<img border="0" src="/images/image.jpg" alt="Image" width="100" height="100" />';
preg_match( '@src="([^"]+)"@' , $html, $match );
$src = array_pop($match);
// will return /images/image.jpg
echo $src;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment