PHP addChild() 函數
PHP addChild() 函數
實例
給 body 元素和 footer 元素添加一個子元素:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
$xml=new SimpleXMLElement($note);
// Add a child element to the body element
$xml->body->addChild("date","2013-01-01");
// Add a child element after the last element inside note
$footer=$xml->addChild("footer","Some footer text");
echo $xml->asXML();
?>
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
$xml=new SimpleXMLElement($note);
// Add a child element to the body element
$xml->body->addChild("date","2013-01-01");
// Add a child element after the last element inside note
$footer=$xml->addChild("footer","Some footer text");
echo $xml->asXML();
?>
運行實例 ?
定義和用法
addChild() 函數給 SimpleXML 元素添加一個子元素。
語法
addChild(name,value,ns);
參數 | 描述 |
---|---|
name | 必需。規定要添加的子元素的名稱。 |
value | 可選。規定子元素的值。 |
ns | 可選。規定子元素的命名空間。 |
技術細節
返回值: | 返回一個表示添加到 XML 中的子元素的 SimpleXMLElement 對象。 |
---|---|
PHP 版本: | 5.1.3+ |

相關文章
- PHP 教程
- PHP 類型比較
- PHP 超級全局變量
- PHP Cookie
- PHP Secure E-mails
- PHP 錯誤處理
- PHP array_column() 函數
- PHP array_combine() 函數
- PHP array_diff_assoc() 函數
- PHP array_key_exists() 函數
- PHP array_pop() 函數
- PHP array_replace() 函數
- PHP array_splice() 函數
- PHP array_uintersect() 函數
- PHP array_uintersect_assoc() 函數
- PHP each() 函數
- PHP in_array() 函數
- PHP key() 函數
- PHP pos() 函數
- PHP PDO