Check whether returned file is XML or not

后端 未结 3 1703
南旧
南旧 2021-01-14 05:33

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 sayi

相关标签:
3条回答
  • 2021-01-14 06:09

    Check if the first 5 characters equal <?xml, that should be a pretty good clue.

    if(substr($output, 0, 5) == "<?xml") {
        echo 'Is XML';
    } else {
        echo 'Not XML';
    }
    
    0 讨论(0)
  • 2021-01-14 06:19
    $result = simplexml_load_string ($data, 'SimpleXmlElement', LIBXML_NOERROR+LIBXML_ERR_FATAL+LIBXML_ERR_NONE);
    if (false == $result) echo 'error';
    
    0 讨论(0)
  • 2021-01-14 06:26

    Could also be because the first line of the return data is blank - try $output = trim($output) before you parse the string as XML.

    0 讨论(0)
提交回复
热议问题