PHP xml_get_current_line_number() 関数

定義と用法

xml_get_current_line_number() 関数は XML パーサーの現在の行番号を取得します。

文法

xml_get_current_line_number(パーサー)
パラメータ 説明
パーサー 必須。使用する XML 解析器を指定します。

説明

もし パーサー パラメータが有効な解析器を指していない場合、この関数は FALSE を返します。それ以外の場合、指定された解析器がキャッシュ中の現在の行号を返します。

<?php
// 無効な XML ファイル
$xmlfile = 'test.xml';
$xmlparser = xml_parser_create();
// ファイルを開きデータを読み取ります
$fp = fopen($xmlfile, 'r');
while ($xmldata = fread($fp, 4096)) 
  {
  // データ ブロックの解析
  if (!xml_parse($xmlparser,$xmldata,feof($fp))) 
    {
    die( print "ERROR: "
    . xml_error_string(xml_get_error_code($xmlparser))
    . "<br />"
    . "行: "
    . xml_get_current_line_number($xmlparser)
    . "<br />"
    . "コラム: "
    . xml_get_current_column_number($xmlparser)
    . "<br />");
    }
  }
xml_parser_free($xmlparser);
?>

出力:

ERROR: タグが一致しません
行: 8
コラム: 61