如何在 PHP 中使用 DOM 创建带有参数的超链接


How to create a hyperlink with parameters using DOM in PHP?

我正在尝试以这种方式使用 DOM 创建一个超链接:

        //create a hyper link
        $hyperlink = $dom->createElement('a',$info[0][id]);
        $url = $dom->createAttribute('href');
        $url->value="http:/mydomain.com/index.php?type=users&user_id=1";
        $hyperlink->appendChild($url);

但是超链接不起作用。当我删除参数时

?类型=用户&user_id=1

然后它工作正常。

我应该如何将这些参数正确传递给超链接?

我使用

@Perry 的建议解决了这个问题,方法是使用 CDATASection 将参数添加到 url

$param = $dom->createCDATASection('?type=users&user_id=1');
$url->appendChild($param);