V Posted July 3, 2010 Share Posted July 3, 2010 I'm trying to use a header that interprets a php file as XML but I get this error. I'm not sure what I'm doing wrong.. This page contains the following errors: error on line 1 at column 1: Document is empty Below is a rendering of the page up to the first error. The php I'm using is header("Content-type: text/xml"); require_once("functions.php"); $connection = dbConnect(); //connects to DB $sql = "SELECT * FROM posts ORDER BY date DESC"; $result = $connection->query($sql) or die(mysqli_error($connection)); $xml_output = "<?xml version=\"1.0\"?>\n"; $xml_output .= "<entries>\n"; while ($row = $result->fetch_assoc()) { $xml_output .= "\t<entry>\n"; $xml_output .= "\t\t<date>" . $row['post_date'] . "</date>\n"; // Escaping illegal characters $row['post_title'] = str_replace("&", "&", $row['post_title']); $row['post_title'] = str_replace("<", "<", $row['post_title']); $row['post_title'] = str_replace(">", ">", $row['post_title']); $row['tpost_title'] = str_replace("\"", """, $row['post_title']); $xml_output .= "\t\t<text>" . $row['post_title'] . "</text>\n"; $xml_output .= "\t</entry>\n"; } $xml_output .= "</entries>"; echo $xml_output; Can someone please share how to fix this? Link to comment https://forums.phpfreaks.com/topic/206649-header-error/ Share on other sites More sharing options...
AbraCadaver Posted July 3, 2010 Share Posted July 3, 2010 That's not a PHP error. Where is it coming from? Also, these don't do anything: $row['post_title'] = str_replace("&", "&", $row['post_title']); $row['post_title'] = str_replace("<", "<", $row['post_title']); You can probably replace all of the str_replace() calls with just this: $xml_output .= "\t\t<text>" . htmlentities($row['post_title']) . "</text>\n"; Link to comment https://forums.phpfreaks.com/topic/206649-header-error/#findComment-1080780 Share on other sites More sharing options...
V Posted July 3, 2010 Author Share Posted July 3, 2010 AbraCadaver thanks for the str_replace() suggestion! I think it was a MYSQLI errror. There was an unknown column. It works now Link to comment https://forums.phpfreaks.com/topic/206649-header-error/#findComment-1080795 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.