Friday, October 10, 2025
HomeLanguagesPHP | xml_parser_get_option() Function

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 described below:

  • $parser: It is required parameter. It specifies the XML parser whose options to be retrieved.
  • $specified_option: It is required parameter (integer). It specifies the options to be retrieved from specified parser.
    Possible values of the parameters are:

    • XML_OPTION_CASE_FOLDING: It is used to specify the case-folding. If it enables then it returns 1 and if it disables then it returns 0.
    • XML_OPTION_TARGET_ENCODING: It is used to specify the target encoding in the specified XML parser. It returns the name of the encoding (US-ASCII, UTF-8 or ISO-8859-1 etc).
    • XML_OPTION_SKIP_TAGSTART: It is used to specify the number of characters skipped in the beginning of a tag name.
    • XML_OPTION_SKIP_WHITE: It is used to specify if values consisting of whitespace characters are skipped or not. It returns 1 if skipped and 0 otherwise.

Return Value: This function returns the value of specified option on success or False on failure.

Note:

  • This function is available for PHP 4.0.0 and newer version.
  • Option parameters XML_OPTION_SKIP_TAGSTART and XML_OPTION_SKIP_WHITE will work for PHP 7.1.0 and newer versions only.

Program 1:




<?php
  
// Creating an XML parser
$parser = xml_parser_create();
  
echo "This example illustrates how xml_parser_get_option()"
        . " function works<br>";
echo "XML_OPTION_CASE_FOLDING: " . xml_parser_get_option(
            $parser, XML_OPTION_CASE_FOLDING) ."<br>";
  
// Free to XML parser
xml_parser_free($parser);
  
?>


Output:

This example show how xml_parser_get_option() function works
XML_OPTION_CASE_FOLDING: 1

Program 2:




<?php
  
// Create an XML parser
$parser = xml_parser_create();
  
// Getting the option for all possible options
echo "option = XML_OPTION_CASE_FOLDING: " . 
    xml_parser_get_option($parser, XML_OPTION_CASE_FOLDING) ."<br>";
  
echo "option = XML_OPTION_TARGET_ENCODING: " .
    xml_parser_get_option($parser, XML_OPTION_TARGET_ENCODING) ."<br>";
  
echo "option = XML_OPTION_SKIP_TAGSTART: " .
    xml_parser_get_option($parser, XML_OPTION_SKIP_TAGSTART) ."<br>";
  
echo "option = XML_OPTION_SKIP_WHITE: " .
    xml_parser_get_option($parser, XML_OPTION_SKIP_WHITE);
  
// Free to 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

Reference: https://www.php.net/manual/en/function.xml-parser-get-option.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS