Skip to content

Instantly share code, notes, and snippets.

@davidchc
Created March 19, 2018 12:52
Show Gist options
  • Save davidchc/63e28fe9a9bb12f22fb64b337a7d8a5e to your computer and use it in GitHub Desktop.
Save davidchc/63e28fe9a9bb12f22fb64b337a7d8a5e to your computer and use it in GitHub Desktop.
<?php
$content = 'jbajdbfkjsd <img src="endereco/imagem1.jpg" />
<img src="endereco/imagem2.jpg" />
<img src="endereco/imagem3.jpg" />
<img src="endereco/imagem4.jpg"/>
';
preg_match_all('/<img[^>]*>/i',$content, $matches);
$srcs = array_map(function($image){
preg_match('/src="([^"]*)"/mis',$image, $matches);
return $matches[1];
}, $matches[0]);
$newContent = preg_replace('/<img[^>]*>/i', '', $content);
echo $newContent;
echo '<hr/>';
echo '<pre>';
print_r($srcs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment