PHP xml_error_string() 函数

PHP XML Parser 函数


定义和用法

xml_error_string() 函数获取 XML 解析器的错误描述。

语法

xml_error_string(errorcode)
参数 描述
errorcode 必需。规定要使用的错误代码。该错误码是 xml_get_error_code() 函数的返回值。

说明

返回与 errorcode 描述的错误代码参数对应的文本描述字符串,若没有与之对应的描述,则返回 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

PHP XML Parser 函数

本教程仅供参考学习,如用于商业带来的问题,本站概不负责。
关注公众号
关注公众号

©2020 IT自习室京ICP备20010815号