它没有将url值从php传递到xml转换
警告:SimpleXMLElement :: __ construct():实体:第141行:解析器错误:EntityRef:期待&#39 ;;'在/home/u395985035/public_html/ddd/ddd.php第34行
警告:第34行/home/u395985035/public_html/ddd/ddd.php中的SimpleXMLElement :: __ construct():http://teko.gogo.com/gtw_c?tem_id=844&erw_id=44545
警告:第34行/home/u395985035/public_html/ddd/ddd.php中的SimpleXMLElement :: __ construct():^
致命错误:未捕获的异常'异常'有消息'字符串可以 不被解析为XML'在/home/u395985035/public_html/ddd/ddd.php:34 堆栈跟踪:#0 /home/u395985035/public_html/ddd/ddd.php(34): SimpleXMLElement-> __构建体(' \ n \吨\吨
<?php
include("config.php");
$sql = "SELECT * FROM table1";
$q = mysqli_query($conn,$sql) or die(mysql_error());
$xml = "<demo1>\n\t\t";
while($r = mysqli_fetch_array($q)) {
$xml .= "<t_view>\n\t";
$xml .= "<l1>".$r['id']."</l1>\n\t\t";
$xml .= "<l2>".$r['link1']."</l2>\n\t\t";
$xml .= "</t_view>\n\t";
}
$xml .= "</demo1>\n\t\t";
$sxe = new SimpleXMLElement($xml);
$sxe->asXML("ddd.xml");
/* I am parsing url link with parameters in $r['link1'] */
?>
答案 0 :(得分:0)
好吧,不要编码你的网址只是试试这个,我已经测试过它正在运行。
while($r = mysqli_fetch_array($q)) {
$xml .= "<t_view>\n\t";
$xml .= "<l1>".$r['id']."</l1>\n\t\t";
$xml .= "<l2>".preg_replace('#&(?=[a-z_0-9]+=)#', '&', $r['link1'])."</l2>\n\t\t";
$xml .= "</t_view>\n\t";
}