echo $ DOM-> saveXML()安全(htmlspecialchars)

时间:2013-10-31 06:20:12

标签: php xml htmlspecialchars

拥有以下代码

$dom = new DOMDocument('1.0','UTF-8');

$root = $dom->createElement('корневой');
$dom->appendChild($root);

$data = [
    ['TransactionPartnerName' => 'Transaction-Partner-Name-1'],
];

foreach ($data as $row) {
    $child11 = $dom->createElement('вложенный', $row['TransactionPartnerName'] );
    $root->appendChild($child11);

    $child_att11 = $dom->createAttribute('vārds');
    $child11->appendChild($child_att11);

    $att_text11 = $dom->createTextNode('Value attribute11');
    $child_att11->appendChild($att_text11);
}

echo $dom->saveXML();

当我看到echo和变量时,始终要使用htmlspecialchars。以下都不起作用:echo htmlspecialchars($dom->saveXML(), ENT_QUOTES, "UTF-8")echo htmlspecialchars($dom, ENT_QUOTES, "UTF-8")->saveXML()

尝试将($row['TransactionPartnerName'])替换为例如<a href="http://www.google.com">google</a>(插入mysql)。在输出中,我看不到超链接,请参阅简单<a href="http://www.google.com">google</a>

那么问题。某处需要htmlspecialchars吗?可以在这里使用(htmlspecialchars(($row['TransactionPartnerName']), ENT_QUOTES, "UTF-8") )

0 个答案:

没有答案