I am trying to create an XML file output in PHP for a remote phone book on an IP Phone, here is the code i have:
<?php
$conn=mysql_connect("localhost","user","********");
mysql_select_db("db_name",$conn);
header("Content-Type: text/xml");
header("Connection: close");
header("Expires: -1");
?>
<YealinkIPPhoneDirectory>
<?php
$output='<YealinkIPPhoneDirectory>\n';
$sql="SELECT * from contacts ";
$rs=mysql_query($sql,$conn);
while($result=mysql_fetch_array($rs)) {
$output .= "<DirectoryEntry>\n";
$output .= "<Name>Mobile:</Name>\n";
$output .= "<Telephone>" . $result["mobile"] . "</Telephone>\n";
$output .= "</DirectoryEntry>\n";
}
$output='</YealinkIPPhoneDirectory>\n';
echo '$output';
?>
but i get this error message:
This page contains the following errors:
error on line 3 at column 8: Extra content at the end of the document
Below is a rendering of the page up to the first error.
$output
<?php
$conn=mysql_connect("localhost","user","********");
mysql_select_db("db_name",$conn);
header("Content-Type: text/xml");
header("Connection: close");
header("Expires: -1");
$output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$output .= '<YealinkIPPhoneDirectory>\n';
$sql="SELECT * from contacts ";
$rs=mysql_query($sql,$conn);
while($result=mysql_fetch_array($rs)) {
$output .= "<DirectoryEntry>\n";
$output .= "<Name>Mobile:</Name>\n";
$output .= "<Telephone>" . $result["mobile"] . "</Telephone>\n";
$output .= "</DirectoryEntry>\n";
}
$output.='</YealinkIPPhoneDirectory>';
echo $output;
?>
You need to remove this line:
echo '$output';
and replace it with this:
echo $output;
Here is a sample:
Note how singlequoted values are literally echoed, so you literally see $output
as your output.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.