Home > Backend Development > PHP Tutorial > PHP获取远程页面输出的xml有关问题

PHP获取远程页面输出的xml有关问题

WBOY
Release: 2016-06-13 13:40:54
Original
1163 people have browsed it

PHP获取远程页面输出的xml问题
需要获取一个远程页面输出的xml信息,那个页面除了xml代码以外,页头还有问题其它信息,

用 simplexml_load_string() 去获取这个内容就提示 Entity: line 1: parser error : Start tag expected, '
还有其它办法获取么到这个信息么, 或者直接不用解析xml文件,只要判断里的内容是什么也可以

XML code

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/xml;charset=UTF-8
Content-Length: 662
Date: Wed, 28 Mar 2012 02:04:43 GMT
Connection: close

<!--?xml version="1.0" encoding="UTF-8" standalone="yes"?-->
<error_response>
<args>
<arg><key>sign</key><value>1B6DF27CC81E98EEBE78F5E4765F2E09</value></arg>
<arg><key>timestamp</key><value>20120328100423</value></arg>
<arg><key>v</key><value>1.0</value></arg>
<arg><key>sign_v</key><value>1</value></arg>
<arg><key>method</key><value>allinpay.card.cardwithproductinfo.get</value></arg>
<arg><key>app_key</key><value>test</value></arg>
<arg><key>format</key><value>xml</value></arg>
<arg><key>password</key><value>5arHL6zxgecGKGQ nqBVQPRth3zEuJMO</value></arg>
<arg><key>card_id</key><value>12345678</value></arg>
</args><code>25</code>
<msg>无效签名  </msg>
</error_response>


Copy after login


------解决方案--------------------
1、不知道你用什么方法获取的,为什么不去除头信息
2、simplexml_load_file 支持 url,直接取得就可以,为什么要先抓取到字符串

------解决方案--------------------
这样试一下
PHP code

$string = 
<args>
<arg><key>sign</key><value>1B6DF27CC81E98EEBE78F5E4765F2E09</value></arg>
<arg><key>timestamp</key><value>20120328100423</value></arg>
<arg><key>v</key><value>1.0</value></arg>
<arg><key>sign_v</key><value>1</value></arg>
<arg><key>method</key><value>allinpay.card.cardwithproductinfo.get</value></arg>
<arg><key>app_key</key><value>test</value></arg>
<arg><key>format</key><value>xml</value></arg>
<arg><key>password</key><value>5arHL6zxgecGKGQ nqBVQPRth3zEuJMO</value></arg>
<arg><key>card_id</key><value>12345678</value></arg>
</args><code>25</code>
<msg>无效签名  </msg>


XML;

echo '<pre class="brush:php;toolbar:false">';
$xml = simplexml_load_string($string);
var_dump($xml);
<br><font color="#e78608">------解决方案--------------------</font><br>
你可以用file_get_contents('aa.xml');然后正则获取。 <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template