PHP | xml_get_current_column_number()函数
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
user123
firstname lastname
+91-9876543210
I am John Doe. Live in Kolkata, India.
PHP
Error Code: " .
// Error code
xml_get_error_code($xml_parser) .
"
Line: " .
// Line number where the error occurred
xml_get_current_line_number($xml_parser) .
"
Column: " .
// Column number where the error occurred
xml_get_current_column_number($xml_parser) .
"
Byte Index: " .
// Byte index where the current byte occurred
xml_get_current_byte_index($xml_parser) . "
"
);
}
}
// Free to XML parser
xml_parser_free($xml_parser);
?>
XML
user123
firstname lastname
+91-9876543210
I am John Doe. Live in Kolkata, India.
PHP
Error Code: " .
// Error code
xml_get_error_code($xml_parser) .
"
Line: " .
// Line number where the error occurred
xml_get_current_line_number($xml_parser) .
"
Column: " .
// Column number where the error occurred
xml_get_current_column_number($xml_parser) .
"
Byte Index: " .
// Byte index where the current byte occurred
xml_get_current_byte_index($xml_parser) . "
"
);
}
}
// Free to XML parser
xml_parser_free($xml_parser);
?>
方案一:
PHP
Error Code: " .
// Error code
xml_get_error_code($xml_parser) .
"
Line: " .
// Line number where the error occurred
xml_get_current_line_number($xml_parser) .
"
Column: " .
// Column number where the error occurred
xml_get_current_column_number($xml_parser) .
"
Byte Index: " .
// Byte index where the current byte occurred
xml_get_current_byte_index($xml_parser) . "
"
);
}
}
// Free to XML parser
xml_parser_free($xml_parser);
?>
输出:
ERROR: Mismatched tag
Error Code: 76
Line: 7
Column: 13
Byte Index: 208
极客.xml 文件:
XML
user123
firstname lastname
+91-9876543210
I am John Doe. Live in Kolkata, India.
方案二:
PHP
Error Code: " .
// Error code
xml_get_error_code($xml_parser) .
"
Line: " .
// Line number where the error occurred
xml_get_current_line_number($xml_parser) .
"
Column: " .
// Column number where the error occurred
xml_get_current_column_number($xml_parser) .
"
Byte Index: " .
// Byte index where the current byte occurred
xml_get_current_byte_index($xml_parser) . "
"
);
}
}
// 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/函数.xml-get-current-column-number。 PHP