php setAttribute replacing & with &


php setAttribute replacing & with &

我想做这样的事情(其中$doc是一个DOMDocument)

$link_found = $doc->getElementsByTagName('a');
foreach ($link_found as $idx => $link) {
    $link->setAttribute('href', "/test.php?t=1&q=2" ) ;
}

一切正常,但在href中现在我得到

"/test.php?t=1&q=2" 

我需要文字&,而不是用&编码

I need

 "/test.php?t=1&q=2"

类似于普通的查询字符串

如果&没有引入实体,则标准要求对其进行转义,即使在属性中。

(这是我在一个句子里用过的最i_的词了…永远…)

$string = html_entity_decode($string); // you're welcome