PHP xml_set_external_entity_ref_handler() Function
Definition and Usage
The xml_set_external_entity_ref_handler() function defines the function to be called when the parser finds an external entity in the XML document.
If the handler is successfully established, the function will return true; otherwise, it will return false.
Syntax
xml_set_external_entity_ref_handler(parser,handler)
Parameter | Description |
---|---|
parser | Required. Defines the XML parser to be used. |
handler | Required. Defines the function to be called when the parser finds an external entity. |
By handler The function specified by the parameter must have six parameters:
Parameter | Description |
---|---|
parser | Required. Defines a variable that contains the XML parser called by the processor. |
name | Required. Defines a variable that contains the name of the external entity. |
base |
Required. Defines a variable that contains the base for the system identifier (system_id) of the external entity. The parameter is usually set to an empty string. |
system_id | Required. Specifies the variable that contains the system identifier of the external entity. |
public_id | Required. Specifies the variable that contains the public identifier of the external entity. |
Description
handler The parameter can also be an array containing object references and method names.
Examples
<?php $parser=xml_parser_create(); function char($parser,$data) { echo $data; } function ext_ent_handler($parser,$ent,$base,$sysID,$pubID) { echo "$ent"; echo "$sysID"; echo "$pubID"; } xml_set_character_data_handler($parser,"char"); xml_set_external_entity_ref_handler($parser, "ext_ent_handler"); $fp=fopen("test.xml","r"); while ($data=fread($fp,4096)) { xml_parse($parser,$data,feof($fp)) or die (sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser))); } xml_parser_free($parser); ?>