PHP leaves unexpected Blank like cause xml to fail

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I need help from php expert. I have simple php page which retrieves
data from MySql and outputs as xml format. Everything works but in xml
file it leave a Blank like at the beginning of the file. Which causes
xml parser to go nuts. How do i avoid that space? I read on other post
- php header call usually does exhibit that behaviour but i tried
taking header our but did not make any difference. Here is a sample:

<?php header("Content-type: text/xml");
include ("../config.php");
$connection = @mysql_connect($host, $user, $pass) or die
mysql_select_db($db) or die (mysql_error());
$query = "SELECT id, date, trim(LEFT(title,60)) as title FROM news
$result = mysql_query($query) or die (mysql_error());
print("<?xml version='1.0' ?>\n");
if (mysql_num_rows($result) > 0)
     print("\t<Title> News</Title>\n");
     print("\t<Prompt>Select for detail</Prompt>\n");

    while($row = mysql_fetch_object($result))
    print(str_replace("'",' ',str_replace("<",' ',str_replace("&", '
',str_replace("</I>", ' ',str_replace("<I>",' ',str_replace("<p>",'
',str_replace("'", ' ', $row->title))))))));
     print("\t\t<URL> =");

    print("<Text>Database Authentication Failed!</Text>\n");


    <?xml version='1.0' ?>
    <Title> News</Title>
    <Prompt>Select for detail</Prompt>

Re: PHP leaves unexpected Blank like cause xml to fail

Quoted text here. Click to load it

PHP does not ouput anything you don't tell it to do. Check all your  
(included) files for newlines outside <?php ?> tags. Probably in config.php

Rik Wasmus

Site Timeline