PHP xml_error_string function ()
Definicja i Wykorzystanie
xml_error_string function (), aby uzyskać opis błędu parsera XML.
Jeśli się powiedzie, funkcja zwraca opis błędu. Jeśli to się nie powiedzie, to zwraca FAŁSZ.
gramatyka
xml_error_string(errorcode)
参数 | 描述 |
---|---|
errorcode | 必需。规定要使用的错误代码。该错误码是 xml_get_error_code() 函数的返回值。 |
Przykłady
<?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);
?>
Wyjście kodu powyżej są następujące:
ERROR: Mismatched tag
Line: 5
Column: 41
Line: 5
Column: 41
Kompletna PHP XML referencyjny