Reply to PHP leaves unexpected Blank like cause xml to fail

Your name:

Reply:


Posted by SA SA on 07/17/07 15:17

Hello,
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:

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

while($row = mysql_fetch_object($result))
{
print("\t<MenuItem>\n");
print("\t\t<Name>");
print(str_replace("'",' ',str_replace("<",' ',str_replace("&", '
',str_replace("</I>", ' ',str_replace("<I>",' ',str_replace("<p>",'
',str_replace("'", ' ', $row->title))))))));
print("</Name>\n");
print("\t\t<URL>http://www.somenews.com/n/xmlNewDetail.php?id=");
print($row->id);
print("</URL>\n");
print("\t</MenuItem>\n");

print("</CiscoIPPhoneMenu>\n");
}
else
{
print("<CiscoIPPhoneText>\n");
print("<Text>Database Authentication Failed!</Text>\n");
print("</CiscoIPPhoneText>\n");
}
?>


***************OUTPUT***********

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация