如何提醒 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 将 return 一条警告消息。从脚本(上面提到的)我将在变量 data 中得到一个输出。

我还需要提醒 return 由 xmlvalidate.php 编辑的警告消息。怎么做?

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

在PHP这边你可以使用libxml_get_errors():

libxml_use_internal_errors(true);

/* do validation stuff here */

$errors = libxml_get_errors();

Dealing with XML errors 在 PHP 中解释说:

The libXMLError object, returned by libxml_get_errors(), contains several properties including the message, line and column (position) of the error.

还有一个加载无效的例子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