PHP xml_error_string() 函數(shù)
定義和用法
xml_error_string() 函數(shù)獲取 XML 解析器的錯(cuò)誤描述。
語法
xml_error_string(errorcode)
參數(shù) | 描述 |
---|---|
errorcode | 必需。規(guī)定要使用的錯(cuò)誤代碼。該錯(cuò)誤碼是 xml_get_error_code() 函數(shù)的返回值。 |
說明
返回與 errorcode 描述的錯(cuò)誤代碼參數(shù)對(duì)應(yīng)的文本描述字符串,若沒有與之對(duì)應(yīng)的描述,則返回 false。
例子
<?php
//無效的 xml 文件
$xmlfile = 'test.xml';
$xmlparser = xml_parser_create();
// open a file and read data
$fp = fopen($xmlfile, 'r');
while ($xmldata = fread($fp, 4096))
{
// parse the data chunk
if (!xml_parse($xmlparser,$xmldata,feof($fp)))
{
die( print "ERROR: "
. xml_error_string(xml_get_error_code($xmlparser))
. "<br />"
. "Line: "
. xml_get_current_line_number($xmlparser)
. "<br />"
. "Column: "
. xml_get_current_column_number($xmlparser)
. "<br />");
}
}
xml_parser_free($xmlparser);
?>
輸出:
ERROR: Mismatched tag Line: 8 Column: 51