这给了我错误
$illegal = array("&", "<", ">", "\");
$legal = array("&", "<", ">", """);
$row['name'] = str_replace($illegal, $legal, $row['name']);
这是代码的主要部分
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<products>\n";
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= "\t<product>\n";
$xml_output .= "\t\t<id>" . $row['id'] . "</id>\n";
// Escaping illegal characters
$illegal = array("&", "<", ">", "\");
$legal = array("&", "<", ">", """);
$row['name'] = str_replace($illegal, $legal, $row['name']);
$xml_output .= "\t\t<name>" . $row['name'] . "</name>\n";
$xml_output .= "\t</product>\n";
}
$xml_output .= "</products>";
echo $xml_output;
我的2个问题是
谢谢。
答案 0 :(得分:4)
$illegal = array("&", "<", ">", "\");
应该是
$illegal = array("&", "<", ">", '"');
此外,请查看使用htmlspecialchars而不是您自己的解决方案。
答案 1 :(得分:0)
:您可以使用microtime()
测试运行时速度http://php.net/manual/en/function.microtime.php
<?php
$time_start = microtime(true);
// your code
$time_end = microtime(true);
$time = $time_end - $time_start;
echo $time;
?>