Hàm xml_error_string () 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ô tả lỗi 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_error_string () trả về mô tả lỗi trình phân tích cú pháp XML.
Cú pháp
xml_error_string(code)
Giá trị tham số
Parameter | Description |
---|---|
code | Required. Specifies an error code from the xml_get_error_code() function |
Chi tiết kỹ thuật
Giá trị trả lại: | Mô tả 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