Change tag attribute value with PHP DOMDocument
$dom = new DOMDocument();$dom->loadHTML('<a href="http://foo.bar/">Click here</a>');foreach ($dom->getElementsByTagName('a') as $item) { $item->setAttribute('href', 'http://google.com/'); echo $dom->saveHTML(); exit;}
$dom = new domDocument;$dom->loadHTML('<a href="http://foo.bar/">Click here</a>');$elements = $dom->getElementsByTagName( 'a' );if($elements instanceof DOMNodeList) foreach($elements as $domElement) $domElement->setAttribute('href', 'http://www.google.com/');