PHP | xml_parser_create_ns() Function
Last Updated :
05 Jan, 2023
Improve
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
// 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
// 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