Last active
April 2, 2024 19:37
-
-
Save vyspiansky/11285153 to your computer and use it in GitHub Desktop.
PHP: get image src attribute (regular expression)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
Hola, es mi caso funciono a la perfección, gracias. Saludos.