Jump to content

Header error


V

Recommended Posts

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

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

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.