如何提醒 php 警告消息


How to alert php warning messages?

function validatexml() {
    var xmlfile = "<?php echo $_SESSION['downxml'];?>";
    $.post('xmlvalidate.php', { xmlfile : xmlfile }, function (data) {
        if ($.trim(data) == 'Y') {
            alert('Xml file is valid against NLM 2.3 DTD');
        } else {
            alert('Xml file is not valid against NLM 2.3 DTD<br>Additional Note: ' + data);
        }
    });
}

如果我通过浏览器执行它,xmlvalidate.php将返回一条警告消息。从脚本(上面提到)中,我将在变量 data 中获得输出。

我还需要提醒xmlvalidate.php返回的警告消息。怎么办?

我已经完成了函数error_get_last()但它只返回最后一条警告消息。我需要收到所有警告消息。我该怎么做?

在 PHP 端你可以使用 libxml_get_errors()

libxml_use_internal_errors(true);
/* do validation stuff here */
$errors = libxml_get_errors();

在PHP中处理XML错误解释了:

由 libxml_get_errors() 返回的 libXMLError 对象包含 多个属性,包括消息、行和列(位置) 的错误。

还有一个加载无效 XML 的示例:

libxml_use_internal_errors(true);
$sxe = simplexml_load_string("<?xml version='1.0'><broken><xml></broken>");
if ($sxe === false) {
    echo "Failed loading XML'n";
    foreach(libxml_get_errors() as $error) {
        echo "'t", $error->message;
    }
}

哪些输出:

Failed loading XML
    Blank needed here
    parsing XML declaration: '?>' expected
    Opening and ending tag mismatch: xml line 1 and broken
    Premature end of data in tag broken line 1