PHP xml_error_string() 函數

定義和用法

xml_error_string() 函數獲取 XML 解析器的錯誤描述。

語法

xml_error_string(errorcode)
參數 描述
errorcode 必需。規定要使用的錯誤代碼。該錯誤碼是 xml_get_error_code() 函數的返回值。

說明

返回與 errorcode 描述的錯誤代碼參數對應的文本描述字符串,若沒有與之對應的描述,則返回 false。

實例

<?php
//無效的 xml 文件
$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: 8
Column: 51