PHP | xml_parser_set_option() Function Last Updated : 31 Oct, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Pre-requisite: XML Basics The xml_parser_set_option() function is an inbuilt function in PHP which is used to set the options in an XML parser. Syntax: bool xml_parser_set_option( resource $parser, int $specified_option, mixed $option_value) Parameters: This function accepts three parameters as mentioned above and described below: $parser: It is required parameter which specifies that the XML parser whose options to be set. $specified_option: It is required parameter which specifies the options to be set for specified parser. Possible values of this parameter are: XML_OPTION_CASE_FOLDING: It is used to check whether case-folding is enabled or not. The value 1 represents enable and 0 represents disable value. XML_OPTION_TARGET_ENCODING: It specifies the target encoding in the specified XML parser. Set the name of the encoding (US-ASCII, UTF-8 or ISO-8859-1 etc). XML_OPTION_SKIP_TAGSTART: It specifies the number of characters is skipped in the beginning of a tag name. XML_OPTION_SKIP_WHITE: It is used to check whether the whitespace characters are skipped or not. The value 1 is used to skip and 0 otherwise. $option_value: It is required parameter which specifies that a new value for the specified option to be set. Return Value: It returns True on success or False on failure. Note: This function is available for PHP 4.0.0 and newer version. Program 1: php <?php // Creating XML parser $parser = xml_parser_create(); // Set the option XML_OPTION_CASE_FOLDING $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!<br>"; } else { // On failure echo "error while setting option XML_OPTION_CASE_FOLDING!<br>"; } // Setting the option XML_OPTION_TARGET_ENCODING $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 to 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 display the result on wrong value. php <?php // Creating an XML parser $parser = xml_parser_create(); // Setting the option XML_OPTION_TARGET_ENCODING $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 to XML parser xml_parser_free($parser); ?> Note: A runtime error will occur for this example as the value is invalid for the option. Output: error while setting option XML_OPTION_TARGET_ENCODING! Reference: https://www.php.net/manual/en/function.xml-parser-set-option.php Comment More infoAdvertise with us Next Article PHP | xml_parser_get_option() Function G gekcho Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-XML Similar Reads PHP | xml_parser_get_option() Function Pre-requisite: XML Basics The xml_parser_get_option() function is an inbuilt function in PHP which retrieves the options from an XML parser. Syntax: mixed xml_parser_get_option( resource $parser, int $specified_option ) Parameters: This function accepts two parameters as mentioned above and describe 2 min read PHP | xml_parse_into_struct() Function The xml_parse_into_struct() function is an inbuilt function in PHP which is used to parse XML data into an array structure. The XML data are parsed into two parallel array structures, first one is index array that contains pointers to the location of the values in the value array and second one is v 4 min read PHP | xml_parse() Function The xml_parse() function is an inbuilt function in PHP which is used to parse XML document. Syntax:Â int xml_parse( resource $xml_parser, string $xml_data, bool $is_final ) Parameter: This function accepts three parameters as mentioned above and described below:Â Â $xml_parser: It is required paramet 3 min read PHP | xml_parser_create_ns() Function The xml_parser_create_ns() function is an inbuilt function in PHP which is used to create an XML parser with namespace support and returns the resource handle. Syntax:Â resource xml_parser_create_ns( string $encoding, string $separator ) Parameters: This function accepts two parameters as mentioned 2 min read PHP | xml_parser_free() Function Pre-requisite: XML BasicsThe xml_parser_free() function is an inbuilt function in PHP which is used to free the XML parser. Syntax:Â Â bool xml_parser_free( resource $parser ) Parameters: This function accepts single parameter $parser which is required. It specifies the reference of XML parser to fre 3 min read PHP | xml_parser_create() Function The xml_parser_create() function is an inbuilt function in PHP which is used to create an XML parser. Syntax:Â resource xml_parser_create( string $encoding ) Parameters: This function accepts single parameter $encoding which is optional. It specifies the character encoding:Â Â for input/output in PHP 3 min read Like