我正在使用启用了 cURL 的 XAMPP,我尝试解析 php 生成的 xml,但出现此错误,请问有什么帮助吗?我的 search.php 代码:
<?php
header("Content-type: text/xml");
$conn=mysql_connect("localhost","root","");
mysql_select_db("places");
$location = $_GET['location'];
$type = $_GET['type'];
if($location!="" && $type != "" ){
$result=mysql_query("select * from accommodation WHERE location='$location' AND type= '$type'");
}
elseif($location != "")
{$result=mysql_query("select * from accommodation WHERE location='$location'");
}
else{echo "ERROR";
}
echo"<places>";
while($row=mysql_fetch_array($result))
{
echo "<place>";
echo "<placeid>$row[ID]</placeid>";
echo "<name>$row[name]</name>";
echo "<type>$row[type]</type>";
echo "<location>$row[location]</location>";
echo "<availableroom>$row[availability]</availableroom>";
echo "</place>";
}
echo"</places>";
mysql_close($conn);
?>
这是我的 cURL 代码:我使用 POST 从另一个页面中的表单获取位置和类型。我也使用了---> echo "The server sent back :"。htmlentities($response); 但我没有得到任何回应,只有相同的错误消息
<?php
$l = $_POST['location'];
$t = $_POST['type'];
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL,"search.php?location=$l&type=$t");
curl_setopt($connection,CURLOPT_RETURNTRANSFER,1);
curl_setopt($connection,CURLOPT_HEADER, 0);
$response = curl_exec($connection);
echo "The server sent back : ". htmlentities($response);
$xml = simplexml_load_string($response);
for($index=0; $index < count($xml->hotel); $index++)
{
echo $xml->hotel[$index]->hotelid . "<br />";
echo $xml->hotel[$index]->name . "<br />";
echo $xml->hotel[$index]->type . "<br />";
echo $xml->hotel[$index]->location . "<br />";
echo $xml->hotel[$index]->availableroom . "<br />";
}
?>