Wednesday, November 20, 2024
Google search engine
HomeLanguagesPHP | xml_parser_create_ns() Function

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

  • $encoding: It is optional parameter. It specifies character encoding 
    • for input/output in PHP 4
    • only for output from PHP 5
    • for 5.0.0 and 5.0.1 default output charset is ISO-8859-1
    • from 5.0.2 default output charset is UTF-8
  • $separator: It is optional parameter. It specifies the output separator for tag name and namespace. Its default value is ” : “.

Return Value:  

  • On Success: It returns a resource handle which is to be used by some other XML functions.
  • On Failure: It returns FALSE. 

Note:  

  • This function is available for PHP 4.0.5 and newer version.
  • These examples may not work on online IDE. So, try to run it on local server or php hosted servers.

Below programs illustrate the xml_parser_create_ns() function in PHP:

Program 1:  

PHP




<?php
 
// Create an XML parser with
// namespace support
$parser = xml_parser_create_ns();
 
// Free the xml parser
xml_parser_free($parser);
 
?>


Output: 

(no output)

Program 2:  

PHP




<?php
 
// Creating an XML parser
// with namespace support
$parser = xml_parser_create_ns();
 
// Free the xml parser
$res = xml_parser_free($parser);
 
// Check parser is created or not
if(!$parser) {
    echo "error occurred!";
}else {
    echo "parser with namespace support has successfully been created";
}
?>


Output: 

parser with namespace support has successfully been created

Reference: https://www.php.net/manual/en/function.xml-parser-create-ns.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

Recent Comments