PHP xml_set_external_entity_ref_handler() 函数

PHP 教程 · 2019-01-30 20:42:26

定义和用法

xml_set_external_entity_ref_handler() 函数规定当解析器在 XML 文档中找到外部实体时被调用的函数。

如果成功,该函数则返回 TRUE。如果失败,则返回 FALSE。

语法


xml_set_external_entity_ref_handler(parser,handler)


参数 描述
parser 必需。规定要使用的 XML 解析器。
handler 必需。规定当解析器找到外部实体时被调用的函数。

由 "handler" 参数规定的函数必须有五个参数:

参数 描述
parser 必需。规定一个变量,包含调用处理器的 XML 解析器。
name 必需。规定一个变量,包含外部实体名称。
base 必需。规定解析外部实体的系统标识符(system_id)的基础。当前该参数通常都被设置为 NULL。
system_id 必需。规定外部实体的系统标识符。
public_id 必需。规定外部实体的公共标识符。

提示和注释

注释:handler 参数也可以是一个包含对象引用和方法名的数组。

实例


<?php
$parser=xml_parser_create();
function char($parser,$data)
  {
  echo $data;
  }
function ext_ent_handler($parser,$ent,$base,$sysID,$pubID)
  {
  echo "$ent<br />";
  echo "$sysID<br />";
  echo "$pubID<BR />";
  }
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);
?>


点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

Writing Apache Modules with Perl and C

Writing Apache Modules with Perl and C

Lincoln Stein、Doug MacEachern / O'Reilly Media, Inc. / 1999-03 / USD 39.95

Apache is the most popular Web server on the Internet because it is free, reliable, and extensible. The availability of the source code and the modular design of Apache makes it possible to extend Web......一起来看看 《Writing Apache Modules with Perl and C》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具