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