How check if a String is a Valid XML with-out Displaying a Warning in PHP

后端 未结 6 1551
梦谈多话
梦谈多话 2020-12-13 03:43

i was trying to check the validity of a string as xml using this simplexml_load_string()Docs function but it displays a lot of warning messages.

How can I check whe

6条回答
  •  有刺的猬
    2020-12-13 04:06

    try this one

    //check if xml is valid document
    public function _isValidXML($xml) {
        $doc = @simplexml_load_string($xml);
        if ($doc) {
            return true; //this is valid
        } else {
            return false; //this is not valid
        }
    }
    

提交回复
热议问题