[Solved] How do I obtain the canonical value using PHP DomDocument?
There are multiple ways to do this. Using XML: <?php $html = “<link rel=”canonical” href=”http://test.com/asdfsdf/sdf/” />”; $xml = simplexml_load_string($html); $attr = $xml->attributes(); print_r($attr); ?> which outputs: SimpleXMLElement Object ( [@attributes] => Array ( [rel] => canonical [href] => http://test.com/asdfsdf/sdf/ ) ) or, using Dom: <?php $html = “<link rel=”canonical” href=”http://test.com/asdfsdf/sdf/” />”; $dom = new DOMDocument; … Read more