Function
xml_parser_get_option()- is a built-in PHP function that extracts parameters from an XML parser.
Syntax:mixed xml_parser_get_option (resource $parser, int $specified_option)
Parameters:This function takes two parameters as above and described below:
- $parser:Required parameter. It defines the XML parser for which parameters are to be retrieved.
- $selected_option:Required parameter (integer). It defines the parameters to be obtained from the specified analyzer.
Possible parameter values: - XML_OPTION_CASE_FOLDING:used to specify foldingcase. If enabled, it returns 1, and if disabled, it returns 0.
- XML_OPTION_TARGET_ENCODING:is used to specify the target encoding in the specified XML parser. Returns the encoding name (US-ASCII, UTF-8 or ISO-8859-1, etc.)
- XML_OPTION_SKIP_TAGSTART:is used to specify the number of characters missing at the beginning of the name tag.
- XML_OPTION_SKIP_WHITE:is used to specify whether values consisting of whitespace are skipped or not. Returns 1 if omitted, 0 otherwise.
Return value:This function returns the value of the specified parameter on success or False on error.
Notes : - This feature is available for PHP 4.0.0 and newer.
- The XML_OPTION_SKIP_TAGSTART and XML_OPTION_SKIP_WHITE options will only work for PHP 7.1.0 and later.
Program 1:
// Create an XML parser
$parser
= xml_parser_create();
echo
" This example illustrates how xml_parser_get_option() "
.
"function works
"
;
echo
"XML_OPTION_CASE_FOLDING:"
. xml_parser_get_option (
$parser
, XML_OPTION_CASE_FOLDING ).
"
"
;
// Free XML parser
xml_parser_free (
$parser
);
?>
Output:This example show how xml_parser_get_option() function works XML_OPTION_CASE_FOLDING: 1
Program 2:
// Create XML parser
$parser
= xml_parser_create();
// Get options for all possible options
echo
"option = XML_OPTION_CASE_FOLDING:"
.
xml_parser_get_option (
$parser
, XML_OPTION_CASE_FOLDING).
"
"
;
echo
" option = XML_OPTION_TARGET_ENCODING: "
.
xml_parser_get_option (
$parser
, XML_OPTION_TARGET_ENCODING).
"
"
;
echo
" option = XML_OPTION_SKIP_TAGSTART: "
.
xml_parser_get_option (
$parser
, XML_OPTION_SKIP_TAGSTART).
"
"
;
echo
" option = XML_OPTION_SKIP_WHITE: "
.
xml_parser_get_option (
$parser
, XML_OPTION_SKIP_WHITE);
// Free XML parser
xml_parser_free (
$parser
);
?>
Output:option = XML_OPTION_CASE_FOLDING: 1 option = XML_OPTION_TARGET_ENCODING: UTF-8 option = XML_OPTION_SKIP_TAGSTART: 0 option = XML_OPTION_SKIP_WHITE: 0
Link: https://www.php.net/manual/en/function.xml-parser-get- option.php