Created
August 16, 2019 13:52
-
-
Save lonalore/ae013be31e46e0977a68e2f9b0b36945 to your computer and use it in GitHub Desktop.
PHP: get image src attribute (regular expression)
This file contains hidden or 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 | |
$html = '<img border="0" src="/images/image1.jpg" alt="Image" width="100" height="100" /> | |
<img border="0" src="/images/image2.jpg" alt="Image" width="100" height="100" /> | |
<img border="0" src="/images/image3.jpg" alt="Image" width="100" height="100" />'; | |
preg_match_all('@src="([^"]+)"@', $html, $match); | |
$src = array_pop($match); | |
print_r($src); | |
// Array ( | |
// [0] => /images/image1.jpg | |
// [1] => /images/image2.jpg | |
// [2] => /images/image3.jpg | |
// ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment