PHP擷取遠程頁面輸出的xml有關問題

來源:互聯網
上載者:User
PHP擷取遠程頁面輸出的xml問題
需要擷取一個遠程頁面輸出的xml資訊,那個頁面除了xml代碼以外,頁頭還有問題其它資訊,

用 simplexml_load_string() 去擷取這個內容就提示 Entity: line 1: parser error : Start tag expected, '<' not found

還有其它辦法擷取麼到這個資訊麼, 或者直接不用解析xml檔案,只要判斷 裡的內容是什麼也可以

XML code
HTTP/1.1 200 OKServer: Apache-Coyote/1.1Content-Type: application/xml;charset=UTF-8Content-Length: 662Date: Wed, 28 Mar 2012 02:04:43 GMTConnection: closesign1B6DF27CC81E98EEBE78F5E4765F2E09timestamp20120328100423v1.0sign_v1methodallinpay.card.cardwithproductinfo.getapp_keytestformatxmlpassword5arHL6zxgecGKGQ nqBVQPRth3zEuJMOcard_id1234567825無效簽名  


------解決方案--------------------
1、不知道你用什麼方法擷取的,為什麼不去除頭資訊
2、simplexml_load_file 支援 url,直接取得就可以,為什麼要先抓取到字串

------解決方案--------------------
這樣試一下
PHP code
$string = <<sign1B6DF27CC81E98EEBE78F5E4765F2E09timestamp20120328100423v1.0sign_v1methodallinpay.card.cardwithproductinfo.getapp_keytestformatxmlpassword5arHL6zxgecGKGQ nqBVQPRth3zEuJMOcard_id1234567825無效簽名  XML;echo '
';$xml = simplexml_load_string($string);var_dump($xml);
------解決方案--------------------
你可以用file_get_contents('aa.xml');然後正則擷取。
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.