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

TUTORIAL BÁSICO DE PHP

PHP TUTORIAL AVANÇADO

PHP & MySQL

PHP Reference Manual

PHP xml_set_default_handler() function usage and example

PHP XML Functions 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 handler specified by parser.

Return value

Returns True on success, false on failure

Parameter

NumberParameters and descriptions
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 as follows

<?php
   $input = xml_parser_create();
   
   function default($input,$data){
      echo $data;
   }
   
   xml_set_default_handler($input,"default");
   
   
   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 Functions Manual