Php/func xml get current byte index
来自菜鸟教程
PHP xml_get_current_byte_index()函数
例
出错时,返回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>Byte Index: "
. xml_get_current_byte_index($xmlparser)
. "<br>");
}
}
xml_parser_free($xmlparser);
?>
上面代码的输出可能是:
ERROR: Mismatched tag Line: 5 Column: 41 Byte Index: 72
定义和用法
xml_get_current_byte_index()函数返回XML解析器的字节索引。
句法
xml_get_current_byte_index(parser)
参数值
| 参数 | 描述 |
|---|---|
| parser | 需要。指定要使用的XML解析器 |
技术细节
| 返回值: | 当前成功的字节索引。失败时为假 |
| PHP版本: | 4.0+ |