检查返回的文件是否为XML [英] Check whether returned file is XML or not
问题描述
我需要检查网站输出的返回值。如果有效的登录详细信息,它返回一个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屋!