开发者

PHP XML error only when "included"

Hi guys I may have to put together a test script to demonstrate this, but I think it should be a obvious answer.

I have a php script that generates an XML document. There are several functions in a common.inc.php.

When I include these functions via require_once the script executes fine but the browser thinks its HTML not xml which through a kink in my parser :)

Wh开发者_运维问答en I cut and paste the same functions in the script it works like a champ.

Any ideas why? Has to be something I am missing with the functionality of require. I tried some of the ob functions no luck.

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


  echo '<?xml version="1.0" encoding="UTF-8"?>';


Typically this happens if there is some sort of output before that xml line. Are you sure your PHP open tag <?php is the very first thing in the file? Be sure to take into account any includes, such as your common.inc.php.

I bet it has a blank line before the open tag, or after the close tag. If you have a file that is entirely PHP, you can simply not close your PHP tag, leaving out ?> altogether. This ensures that any line breaks at the end of the file aren't sent to the browser. You still need to be mindful of the beginning of the file though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜