检查返回的文件是否为XML [英] Check whether returned file is XML or not

查看:182
本文介绍了检查返回的文件是否为XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查网站输出的返回值。如果有效的登录详细信息,它返回一个XML文件,如果无效的登录详细信息,它只返回一个字符串您输入了无效的ID。



我的问题是我使用这段代码检查,

  $ ch = curl_init(); 

curl_setopt($ ch,CURLOPT_URL,$ url);

curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);

$ output = curl_exec($ ch);

curl_close($ ch);

if(simplexml_load_string($ output)){
echo'是XML';
} else {
echo'不是XML';
}

问题是检查和显示消息,错误



警告:simplexml_load_string()[function.simplexml-load-string]:
实体:第1行:parser错误:



警告:simplexml_load_string()[function.simplexml-load-string]:



警告:simplexml_load_string()[function.simplexml-load-string]:^
in


有没有办法来整理这些错误。



感谢

解决方案

  $ result = simplexml_load_string($ data,'SimpleXmlElement',LIBXML_NOERROR + LIBXML_ERR_FATAL + LIBXML_ERR_NONE); 
if(false == $ result)echo'error';


I need to check the return value of a website output. In case of valid login details it returns a XML file and in case of invalid login details it just returns a string saying "You entered a invalid id".

My problem is I have used this code to check,

$ch = curl_init();

            curl_setopt($ch, CURLOPT_URL, $url);

            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

            $output = curl_exec($ch);

            curl_close($ch);

            if(simplexml_load_string($output)){
                echo 'Is XML';
             }else{
               echo 'Not XML';
                 }

The problem is it is checking and displaying the message, but I am getting these errors

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Start tag expected, '<' not found in

Warning: simplexml_load_string() [function.simplexml-load-string]:

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in

Is there a way to sort out these errors. I have been searching in the internet for the past hour without any success.

Thanks

解决方案

$result = simplexml_load_string ($data, 'SimpleXmlElement', LIBXML_NOERROR+LIBXML_ERR_FATAL+LIBXML_ERR_NONE);
if (false == $result) echo 'error';

这篇关于检查返回的文件是否为XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆