DOM XML (PHP 4) 函数
在线手册:中文 英文
PHP手册

DomDocument::create_text_node

(PHP 4 >= 4.1.0)

DomDocument::create_text_nodeCreate new text node

说明

domtext DomDocument::create_text_node ( string $content )

This function returns a new instance of class DomText. The content of the text is the value of the passed parameter. 此节点出现在文档中,除非是用诸如 domnode_append_child() 等函数来将其插入。

The return value is FALSE if an error occurred.

See also domnode_append_child(), domdocument_create_element(), domdocument_create_comment(), domdocument_create_text(), domdocument_create_attribute(), domdocument_create_processing_instruction(), domdocument_create_entity_reference(), and domnode_insert_before().


DOM XML (PHP 4) 函数
在线手册:中文 英文
PHP手册
PHP手册 - N: Create new text node

用户评论:

chregu at php dot net (12-Dec-2002 12:29)

Or just use utf8_encode($text), at least if your input is iso-8859-1

all text methods in domxml expect utf-8 encoded strings as input.

hlubek at networkteam dot com (01-Jun-2002 05:15)

Ever tried to insert special characters e.g. German ,,, with this function?
Or to mix normal text with entities?

In my scripts I use a function like this:

$translateSpecial = array(
"" => "#228",
"" => "#252",
"" => "#246",
"" => "#196",
"" => "#220",
"" => "#214",
"" => "#223"
);

$buffer = "";
for($i = 0; $i < strlen($value); $i++)
{
  if(!$translateSpecial[$value{$i}])
    $buffer .= $value{$i};
  else
  {
    $node->append_child($xmldoc->create_text_node($buffer));
    $buffer = "";
    $node->append_child($xmldoc->
    create_entity_reference($translateSpecial[$value{$i}]));
  }
}
$node->append_child($xmldoc->create_text_node($buffer));