“Func simplexml addattribute”的版本间差异
本页内容
(创建页面,内容为“{{DISPLAYTITLE:addAttribute()}}2 = PHP addAttribute() 函数 = PHP SimpleXML 参考手册 给根元素和 body 元素添加一个属性: <sample title="" desc="" lang="php" hererun="1">example_start <?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); $xml->addAttribute…”) |
(没有差异)
|
2022年8月17日 (三) 22:28的最新版本
PHP addAttribute() 函数
给根元素和 body 元素添加一个属性:
示例
<?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);
$xml->addAttribute("type","private");
$xml->body->addAttribute("date","2013-01-01");
echo $xml->asXML();
?>
定义和用法
addAttribute() 函数给 SimpleXML 元素添加一个属性。
语法
addAttribute(name,value,ns);
参数 | 描述 |
---|---|
name | 必需。规定要添加的属性的名称。 |
value | 可选。规定属性的值。 |
ns | 可选。规定属性的命名空间。 |
技术细节
返回值: | 没有返回值。 |
PHP 版本: | 5.1.3+ |