xml_set_processing_instruction_handler
(PHP 4, PHP 5)
xml_set_processing_instruction_handler — 建立处理指令(PI)处理器
说明
为 parser 参数指定的 XML 解析器建立处理指令(PI)处理器函数。参数 start_element_handler 和 end_element_handler 为表示函数名称的字符串,这些函数必须在为 parser 指定的解析器调用 xml_parse() 函数时已存在。
处理指令有如下格式:
<?
?>
您可以将 PHP 代码放置在类似的标识符中,但要注意一个限制:在 XML 处理指令(PI)中,PI 的终止符(?>)不能被引号引用,因此该字符序列不应该在您用 PI 嵌入到 XML 文档中的 PHP 代码中出现。否则,剩下的 PHP 代码,包括“真正”的 PI 终止符将被当作字符数据处理。
由 handler 参数命名的函数名必须接受三个参数:
$parser
, string $target
, string $data
)-
parser - 第一个参数 parser 为指向要调用处理器的 XML 解析器的指针。
-
target -
第二个参数
target为 PI 对象(PI target)。 -
data -
第二个参数
target为 PI 数据(PI data)。
如果处理器函数名被设置为空字符串或者 FALSE,则该有问题的处理器将被屏蔽。
如果处理器被成功的建立,该函数将返回 TRUE;如果 parser 指向的不是合法的解析器,函数该函数将返回 FALSE。
Note: 除了函数名,含有对象引用的数组和方法名也可以作为参数。
参数
-
parser -
A reference to the XML parser to set up processing instruction (PI) handler function.
-
handler -
handleris a string containing the name of a function that must exist when xml_parse() is called forparser.The function named by
handlermust accept three parameters:handler ( resource$parser, string$target, string$data)-
parser - The first parameter, parser, is a reference to the XML parser calling the handler.
-
target -
The second parameter,
target, contains the PI target. -
data -
The third parameter,
data, contains the PI data.
If a handler function is set to an empty string, or
FALSE, the handler in question is disabled.Note: 除了函数名,含有对象引用的数组和方法名也可以作为参数。
-
返回值
成功时返回 TRUE, 或者在失败时返回 FALSE.
