English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP xml_set_default_handler() Function Usage and Example

PHP XML Function Manual

The xml_set_default_handler() function is used to establish the default data handler for the XML parser.

Syntax

xml_set_default_handler(parser,handler)

Definition and Usage

 Establishes the default handler function for the XML parser specified by parser.

Return Value

Returns True on success, false on failure

Parameter

NumberParameters and Description
1

parser

XML parser reference used to establish the default handler function.

2

handler

It is used to specify the function used as the event handler

Online Example

Try the following example, file name: sample.xml

<?xml version = "1.0" encoding = "UTF-8"?>
<note>
   <to>Tove</to>/to>
   <from>Jani</from>/from>
   <heading>Reminder</heading>/heading>
   Don't forget me this weekend!
</note>

The following PHP code is given below

<?php
   $input = xml_parser_create();
   
   function default($input,$data){
      echo $data;
   }
   
   xml_set_default_handler($input,"default");
   $fp = fopen("sample.xml","w");
   
   while ($data=fread($fp,4096)) {
      xml_parse($input,$data,feof($fp)) || 
      die (sprintf("XML Error: %s at line %d", 
      
      xml_error_string(xml_get_error_code($input)),
      xml_get_current_line_number($input)));
   }
   xml_parser_free($input);
?>

Output Result

Tove Jani Reminder Don't forget me this weekend!

PHP XML Function Manual