PHP xml_error_string () ฟังก์ชัน
ความหมายและการใช้งาน
xml_error_string () ฟังก์ชันที่จะได้รับตัวแยกวิเคราะห์ XML อธิบายข้อผิดพลาด
หากประสบความสำเร็จฟังก์ชันจะส่งกลับคำอธิบายข้อผิดพลาด หากล้มเหลวก็จะส่งกลับ FALSE
ไวยากรณ์
xml_error_string(errorcode)
参数 | 描述 |
---|---|
errorcode | 必需。规定要使用的错误代码。该错误码是 xml_get_error_code() 函数的返回值。 |
ตัวอย่าง
<?php
//invalid xml file
$xmlfile = 'test.xml';
$xmlparser = xml_parser_create();
// open a 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);
?>
//invalid xml file
$xmlfile = 'test.xml';
$xmlparser = xml_parser_create();
// open a 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);
?>
การส่งออกของโค้ดข้างต้นจะเป็นดังนี้:
ERROR: Mismatched tag
Line: 5
Column: 41
Line: 5
Column: 41
อ้างอิง XML สมบูรณ์ PHP