main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$data = <<<HTML
  <img src="/images/blog/outra-imagem-A.jpg" />
  <img src="/images/blog/outra-imagem-B.jpg" />
  <img id="img_blog" src="/images/blog/cliente-ideal-voce-sabe-quem-e.jpg" />
  <img src="/images/blog/outra-imagem-C.jpg" />
  <img src="/images/blog/outra-imagem-D.jpg" />
HTML;

$dom = new DOMDocument();
$dom->loadHTML($data);

$img = $dom->getElementById("img_blog");

echo $img->getAttribute("src"), PHP_EOL;
PHP 7.0.8 (Legacy: use the following for new features: Command-line PHP: https://repl.it/languages/php_cli PHP Web Server: https://repl.it/languages/php7