dongshao1156 2010-10-21 03:22
浏览 56
已采纳

无法从PHP发送content-type:text / xml标头,同时从MYSQL获取数据

i hope you can cast some light on my problem. I need to do an AJAX / PHP / MYSQL application to display posts and stuff on the page i'm writing.

I only discovered how to do some simple stuff in PHP after taking some mushrooms but that was years ago and now i don't have mushrooms and i'm just stuck!

So here's the problem:

i think i need to send a proper "xml" file through php so the ajax part can take it but: when i try to put the header on top of the php it displays this error:

" Extra content at the end of the document "

When i looked at some tutorials people were using the "header" fearlesly to do such stuff as i want to do and no comments suggested that it didn't work. so why it doesn't work on my local server?

I'm running:

WAMP Apache 2.2.11 PHP 5.3.0

It also doesn't work on a remote server (PHP 5.3.0) :/

I read all the stuff i could find till 5am and decided to ask you for help for the first time :)

Thank you!

header('content-type: application/xhtml+xml; charset=utf-8'); 
require_once("allyouneed.php");
require_once("bazingablob.php"); 

$category=$_GET["category"];
$post_tags=$_GET["post_tags"];
$language=$_GET["language"];
$author=$_GET["author"];
$posts_per_page=$_GET["posts_per_page"];
$current_page=$_GET["current_page"];
$order=$_GET["order"];
$hard_limit=$_GET["hard_limit"];
$show_hidden=$_GET["show_hidden"];*/

$wypluj="";
$wypluj="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";    

$bazinga_blob = new bazingablob;

if (!$bazinga_blob->connect_to_database()) 

        {   
            $wypluj.="<IsOK>0</IsOK>";
            echo $wypluj;
            exit;
        }

        else

        {

            $wypluj.="<IsOK>jedziem</IsOK>";                                        

        }


$bb_result=$bazinga_blob->get_all_posts($category,$post_tags,$language,$author,$posts_per_page,$current_page,$order,$hard_limit,$show_hidden);

if ($bb_result) //udalo sie cos znalezc w bazie wedlug kryteriow

        {

            $wypluj.="<Pagination>";

                $wypluj.="<CurrentPage>";

                $wypluj.=$bazinga_blob->posts_pagination["current_page"];

                $wypluj.="</CurrentPage>";

                $wypluj.="<LastPage>";

                $wypluj.=$bazinga_blob->posts_pagination["last_page"];

                $wypluj.="</LastPage>";

                $wypluj.="<PostsCount>";

                $wypluj.=$bazinga_blob->posts_pagination["posts_count"];

                $wypluj.="</PostsCount>";

            $wypluj.="</Pagination>";


            $wypluj.="<Posts>";


                    foreach ($bb_result as $item) 

                    {

                        $wypluj.="<Post>";

                        $wypluj.="<PostId>".$item->post_id."</PostId>";
                        $wypluj.="<PostAuthor>".$item->post_author."</PostAuthor>";
                        $wypluj.="<PostLangId>".$item->post_langid."</PostLangId>";
                        $wypluj.="<PostSlug>".$item->post_slug."</PostSlug>";
                        $wypluj.="<PostTitle>".$item->post_title."</PostTitle>";
                        $wypluj.="<PostGreetingPicture>".$item->post_greeting_picture."</PostGreetingPicture>";
                        $wypluj.="<PostGreetingVideo>".$item->post_greeting_video."</PostGreetingVideo>";
                        $wypluj.="<PostGreetingSound>".$item->post_greeting_sound."</PostGreetingSound>";
                        $wypluj.="<PostShort>".$item->post_short."</PostShort>";
                        $wypluj.="<PostBody>".$item->post_body."</PostBody>";
                        $wypluj.="<PostDate>".$item->post_date."</PostDate>";
                        $wypluj.="<PostPublished>".$item->post_published."</PostPublished>";
                        $wypluj.="<PostSticky>".$item->post_sticky."</PostSticky>";
                        $wypluj.="<PostComments>".$item->post_comments."</PostComments>";
                        $wypluj.="<PostProtected>".$item->post_protected."</PostProtected>";
                        $wypluj.="</Post>";

                    }

            $wypluj.="</Posts>";



        }


echo $wypluj;
  • 写回答

3条回答 默认 最新

  • douwei3280 2010-10-21 03:43
    关注

    The error comes from your browser and indicates that your XML is malformed.

    Setting the application/xhtml+xml header tells the browser to process the document as serious XML. XML needs to be "well-formed", i.e. it must not contain any syntax errors. Apparently you do have a syntax error on line 1 at column 73, which makes the browser abort the attempt to process the document.

    For this reason it's a pain to hand-code XML, you should really look into a library that takes care of the well-formedness for you, like PHP's own XMLWriter.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口