PHP xml_get_current_line_number()関数
完全な PHP XML リファレンスマニュアル
定義と用法
xml_get_current_line_number() 関数は XML パーサーの現在の行番号を取得します。
成功した場合、この関数は現在の行番号を返します。失敗した場合は FALSE を返します。
構文
xml_get_current_line_number(parser)
| パラメータ | 説明 |
|---|---|
| parser | 必須です。使用する XML パーサーを指定します。 |
例
<?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
完全な PHP XML リファレンスマニュアル その他の拡張