Hàm xml_get_error_code () 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ả lại mã lỗi 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_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: 76
Line: 5
Column: 41
Định nghĩa và Cách sử dụng
Hàm xml_get_error_code () trả về mã lỗi trình phân tích cú pháp XML.
Cú pháp
xml_get_error_code(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: | Mã lỗi 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