xml_get_current_column_number()函數是PHP中的內置函數,用於獲取給定解析器的當前列號。
用法:
int xml_get_current_column_number( resource $xml_parser )
參數:該函數接受單個參數$xml_parser。此參數保存XML解析器的引用,從該引用中獲取列號。
返回值:此函數返回當前成功運行指定xml解析器或失敗時返回False的列號。
注意:
- 此函數可用於PHP 4.0.0和更高版本。
- 這些示例可能不適用於在線IDE。因此,請嘗試在本地服務器或php托管服務器上運行它。
gfg.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<user>
<username> user123 </username>
<name> firstname lastname </name>
<phone> +91-9876543210 </phone>
<detail> I am John Doe. Live in Kolkata, India. </detail>
</users>
程序1:
<?php
// XML file containing mismatch tags
$xml_file = 'gfg.xml';
// XML parser initialization
$xml_parser = xml_parser_create();
// File opening in read mode
$file_pointer = fopen($xml_file, 'r');
// Reading data from the file stream
while ($xml_data = fread($file_pointer, 4096)) {
// Parse the data chunk
if(!xml_parse($xml_parser, $xml_data,
feof($file_pointer))) {
// Displaying errors
die( print "ERROR: " .
// Error string
xml_error_string(xml_get_error_code($xml_parser)) .
"<br/>Error Code: " .
// Error code
xml_get_error_code($xml_parser) .
"<br/>Line: " .
// Line number where the error occured
xml_get_current_line_number($xml_parser) .
"<br/>Column: " .
// Column number where the error occured
xml_get_current_column_number($xml_parser) .
"<br/>Byte Index: " .
// Byte index where the current byte occured
xml_get_current_byte_index($xml_parser) . "<br/>"
);
}
}
// Free to XML parser
xml_parser_free($xml_parser);
?>
輸出:
ERROR: Mismatched tag Error Code: 76 Line: 7 Column: 13 Byte Index: 208
geeks.xml文件:
<?xml version="1.0 encoding="utf-8"?>
<user>
<username> user123 </username>
<name> firstname lastname </name>
<phone> +91-9876543210 </phone>
<detail> I am John Doe. Live in Kolkata, India. </detail>
</user>
程序2:
<?php
// XML file containing mismatch tags
$xml_file = 'geeks.xml';
// XML parser initialization
$xml_parser = xml_parser_create();
// File opening in read mode
$file_pointer = fopen($xml_file, 'r');
// Reading data from the file stream
while ($xml_data = fread($file_pointer, 4096)) {
// Parse the data chunk
if(!xml_parse($xml_parser, $xml_data,
feof($file_pointer))) {
// Displaying errors
die( print "ERROR: " .
// Error string
xml_error_string(xml_get_error_code($xml_parser)) .
"<br/>Error Code: " .
// Error code
xml_get_error_code($xml_parser) .
"<br/>Line: " .
// Line number where the error occured
xml_get_current_line_number($xml_parser) .
"<br/>Column: " .
// Column number where the error occured
xml_get_current_column_number($xml_parser) .
"<br/>Byte Index: " .
// Byte index where the current byte occured
xml_get_current_byte_index($xml_parser) . "<br/>"
);
}
}
// Free to XML parser
xml_parser_free($xml_parser);
?>
輸出:
ERROR: String not closed expecting " or ' Error Code: 34 Line: 1 Column: 36 Byte Index: 37
參考: https://www.php.net/manual/en/function.xml-get-current-column-number.php
相關用法
- p5.js sq()用法及代碼示例
- d3.js d3.map.has()用法及代碼示例
- PHP next()用法及代碼示例
- p5.js day()用法及代碼示例
- p5.js pow()用法及代碼示例
- CSS var()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP pow( )用法及代碼示例
- PHP pi( )用法及代碼示例
- PHP Ds\Map get()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- p5.js str()用法及代碼示例
注:本文由純淨天空篩選整理自gekcho大神的英文原創作品 PHP | xml_get_current_column_number() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。