Php/func xml get current line number
来自菜鸟教程
PHP xml_get_current_line_number()函数
例
出错时,返回XML解析器错误描述,行号和列号:
<?php
// Invalid xml file
$xmlfile = 'test.xml';
$xmlparser = xml_parser_create();
// Open the 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: 5 Column: 41
定义和用法
xml_get_current_line_number()函数返回XML解析器的当前行号。
句法
xml_get_current_line_number(parser)
参数值
| 参数 | 描述 |
|---|---|
| parser | 需要。指定要使用的XML解析器 |
技术细节
| 返回值: | 当前行号成功。失败时为假 |
| PHP版本: | 4.0+ |