Jump to content

PHP MYSQL to XML


Morty222

Recommended Posts

I am getting the data back to xml, just getting this error:

 

Whitespace is not allowed at this location.

 

  <name>A & E Mailers</name>

------------^

 

Dont know how to get the white space out. Any suggestions?

 

Code below:

 

<?php

 

header("Content-type: text/xml");

 

include('mysql.php');

 

$query = "select * from tbl_customers ORDER BY name asc";

$resultID = mysql_query($query);

 

$xml_output = "<?xml version=\"1.0\"?>\n";

$xml_output .= "<customers>\n";

 

for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){

    $row = mysql_fetch_assoc($resultID);

    $xml_output .= "\t<entry>\n";

 

        // Escaping illegal characters

        $row['name'] = str_replace("&", "&", $row['name']);

        $row['name'] = str_replace("<", "<", $row['name']);

        $row['name'] = str_replace(">", ">", $row['name']);

        $row['name'] = str_replace("\"", """, $row['name']);

 

    $xml_output .= "\t\t<name>" . $row['name'] . "</name>\n";

 

$xml_output .= "\t</entry>\n";

}

 

$xml_output .= "</customers>";

 

echo $xml_output;

 

?>

Link to comment
https://forums.phpfreaks.com/topic/127864-php-mysql-to-xml/#findComment-662021
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.