Change language

PHP Xml_parser_set_option () function

Function xml_parser_set_option()- it is a built-in function in PHP that is used to set parameters in an XML parser.Syntax:
bool xml_parser_set_option ( resource $parser, int $specified_option, mixed $option_value)
Parameters:this function takes three parameters, as above and described below:
  • $parser:a required parameter that specifies the XML parser whose parameters are to be set.
  • $specified_option:is a required parameter that specifies the parameters to be set for the specified parser. 
    Possible values ​​for this parameter:
    • XML_OPTION_CASE_FOLDING:is used to check if case folding is enabled or not. A value of 1 represents permission and 0 represents a disable value.
    • XML_OPTION_TARGET_ENCODING:specifies the target encoding in the specified XML parser. Set the encoding name (US-ASCII, UTF-8 or ISO-8859-1, etc.)
    • XML_OPTION_SKIP_TAGSTART:specifies the number of characters skipped at the beginning of the tag name.
    • XML_OPTION_SKIP_WHITE:is used to check if whitespace characters are missing or not. A value of 1 is used to skip and 0 otherwise.
  • $option_value:This is a required parameter and indicates that a new value will be set for the specified options.
Return value:Returns True on success or False on failure.Note.This feature is available for PHP 4.0.0 and later.Program 1: < ? php  
// Create an XML parser $parser = xml_parser_create();  
// Set the XML_OPTION_CASE_FOLDING option $res = xml_parser_set_option ( $parser , XML_OPTION_CASE_FOLDING, 0); if ( $res ) { // On success echo "option XML_OPTION_CASE_FOLDING has successfully been set!
"
; } else { // On failure echo "error while setting option XML_OPTION_CASE_FOLDING!
"
; }  
// Setting the XML_OPTION_TARGET_ENCODING option $res = xml_parser_set_option ( $parser , XML_OPTION_TARGET_ENCODING, ’UTF-8’ ); if ( $res ) { // On success echo "option XML_OPTION_TARGET_ENCODING has successfully been set!" ; } else { // On failure echo "error while setting option XML_OPTION_TARGET_ENCODING!" ; }  
// Free XML parser xml_parser_free ( $parser );  
?>
Output:
option XML_OPTION_CASE_FOLDING has successfully been set! option XML_OPTION_TARGET_ENCODING has successfully been set!
Program 2:This program displays the result at the wrong value.  
// Create an XML parser $parser = xml_parser_create();  
// Setting the XML_OPTION_TARGET_ENCODING option $res = xml_parser_set_option ( $parser , XML_OPTION_TARGET_ENCODING, ’ 0’ ); if ( $res ) { // On success echo "option XML_OPTION_TARGET_ENCODING has successfully been set!" ; } else { // On failure echo "error while setting option XML_OPTION_TARGET_ENCODING!" ; }  
// Free XML parser xml_parser_free ( $parser );  
?>
Note.In this example a runtime error will occur because the value is not valid for the parameter. 
Exit :
error while setting option XML_OPTION_TARGET_ENCODING!
Link: https://www.php.net/manual/en/function.xml-parser-set-option.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method