PHP addAttribute() 函数

PHP 教程 · 2019-01-29 05:56:58

实例

给根元素和 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+

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

查看所有标签

Types and Programming Languages

Types and Programming Languages

Benjamin C. Pierce / The MIT Press / 2002-2-1 / USD 95.00

A type system is a syntactic method for automatically checking the absence of certain erroneous behaviors by classifying program phrases according to the kinds of values they compute. The study of typ......一起来看看 《Types and Programming Languages》 这本书的介绍吧!

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

在线压缩/解压 HTML 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具