Skip to content

Instantly share code, notes, and snippets.

@clevertonh
Created June 17, 2015 20:45
Show Gist options
  • Select an option

  • Save clevertonh/7550b141f85b8fa7db06 to your computer and use it in GitHub Desktop.

Select an option

Save clevertonh/7550b141f85b8fa7db06 to your computer and use it in GitHub Desktop.
Cria um ARRAY com todos os links que achar dentro do código HTML.
<?php
$lstLink = "";
$texto_html = '<html>
<head></head>
<body>
<a href="www.google.com">Link 1</a>
<a href="www.globo.com">Link 2</a>
<a href="www.facebook.com">Link 3</a>
</body>
</html>';
$objDom = new DOMDocument;
$objDom->loadHTML($texto_html);
foreach ($objDom->getElementsByTagName('a') as $node){
$lstLink[] = $node->getAttribute("href");
}
print_r($lstLink);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment