<?php $html = <<<'HTML' <html> <body> <a href="link.tld">Text<a> <a name="bla">Text<a> </body> </html> HTML; function urlHasString($url, $strings) { foreach($strings as $string) { if((FALSE !== strpos($url, $string))) { return false; } } return true; } function getAllLinks($html){ $dom = new DOMDocument(); if(@$dom->loadHTML($html)) { $xpath = new DOMXpath($dom); $anchors = $xpath->evaluate('//a[normalize-space(@href) != ""]'); foreach($anchors as $element) { $new_href =""; $href = $element->getAttribute('href'); $strings = array('#', 'java', 'jpg', 'jpeg', 'png', 'tel', 'pdf'); echo $href.": ".(urlHasString($href, $strings))."<br>"; } } return; } getAllLinks($html);
You have javascript disabled. You will not be able to edit any code.