Hàm xml_get_current_byte_index () trong PHP
❮ Tham chiếu trình phân tích cú pháp XML PHP
Thí dụ
Nếu bị lỗi, hãy trả về mô tả lỗi phân tích cú pháp XML, số dòng, số cột và chỉ mục byte:
<?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);
?>
Đầu ra của đoạn mã trên có thể là:
ERROR: Mismatched tag
Line: 5
Column: 41
Byte Index: 72
Định nghĩa và Cách sử dụng
Hàm xml_get_current_byte_index () trả về chỉ mục byte cho trình phân tích cú pháp XML.
Cú pháp
xml_get_current_byte_index(parser)
Giá trị tham số
Parameter | Description |
---|---|
parser | Required. Specifies the XML parser to use |
Chi tiết kỹ thuật
Giá trị trả lại: | Chỉ số byte hiện tại về thành công. FALSE khi thất bại |
---|---|
Phiên bản PHP: | 4.0+ |
❮ Tham chiếu trình phân tích cú pháp XML PHP