PHP _construct()函数讲解
PHP _construct() 函数
实例
函数创建一个新的 SimpleXMLElement 对象,然后输出 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); echo $xml->body; ?>
[运行实例»](/try/showphp.php?filename=demo_func_simplexml_construct)
定义和用法
_construct()
函数创建一个新的 SimpleXMLElement 对象。
语法
_construct( _data,options,data_is_url,ns,is_prefix_ );
假设我们有如下的 XML 文件,"note.xml":
<?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
实例 1
从 URL 中创建一个 SimpleXMLElement 对象:
<?php $xml=new SimpleXMLElement("note.xml",NULL,TRUE); echo $xml->asXML(); ?>
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对我们的支持。如果你想了解更多相关内容请查看下面相关链接
相关推荐
-
PHP getName()函数讲解
PHP getName() 函数 实例 返回 XML 元素及其子元素的名称: <?php $xml=<<<XML <?xml version="1.0" standalone="yes"?> <cars> <car id="1">Volvo</car> <car id="2">BMW</car> <car id="3
-
PHP asXML()函数讲解
PHP asXML()函数 实例 格式化 XML(版本 1.0)中的 SimpleXML 对象的数据: <?php $note=<<<XML <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </not
-
PHP getNamespaces()函数讲解
PHP getNamespaces() 函数 实例 返回 XML 文档中使用的命名空间: <?php $xml=<<<XML <?xml version="1.0" standalone="yes"?> <cars xmlns:c="http://codingdict.com/ns" xmlns:a="http://codingdict.com/country"> <c:c
-
PHP children()函数讲解
PHP children() 函数 实例 查找 note 节点的子节点: <?php $note=<<<XML <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> XML; $xml
-
PHP addAttribute()函数讲解
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>
-
PHP simplexml_import_dom()函数讲解
PHP simplexml_import_dom() 函数 实例 获取 DOM 文档节点并转换为 SimpleXML 节点: <?php $dom=new domDocument; $dom->loadXML("<note><to>Tove</to><from>Jani</from></note>"); $x=simplexml_import_dom($dom); echo $x->from; ?
-
PHP count()函数讲解
PHP count() 函数 实例 计算 car 节点的子节点个数: <?php $xml=<<<XML <cars> <car name="Volvo"> <child/> <child/> <child/> <child/> </car> <car name="BMW"> <child/> <child/> </c
-
PHP getDocNamespaces()函数讲解
PHP getDocNamespaces() 函数 实例 返回 XML 文档的根节点中声明的命名空间: <?php $xml=<<<XML <?xml version="1.0" standalone="yes"?> <cars xmlns:c="http://codingdict.com/ns"> <c:car id="1">Volvo</c:car>
-
PHP registerXPathNamespace()函数讲解
PHP registerXPathNamespace() 函数 实例 为下一个 XPath 查询创建命名空间上下文: <?php $xml=<<<XML <book xmlns:chap="http://example.org/chapter-title"> <title>My Book</title> <chapter id="1"> <chap:title>Chapter 1&l
-
PHP attributes()函数讲解
PHP attributes() 函数 实例 返回 XML 的 body 元素的属性和值: <?php $note=<<<XML <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body date="2013-01-01" type="private">Don'
随机推荐
- 五款PHP代码重构工具推荐
- Python实现比较两个文件夹中代码变化的方法
- Linux监控cpu以及内存使用情况之top命令(详解)
- 非常有用的40款jQuery 插件推荐(系列二)
- 微信小程序中的swiper组件详解
- Windows系统清理QQ聊天记录、反监控QQ聊天的BAT脚本分享
- PHP 编写大型网站问题集
- thinkPHP实现瀑布流的方法
- Android系统自带样式 (android:theme)
- node.js中的console.time方法使用说明
- AJAX +SpringMVC 实现bootstrap模态框的分页查询功能
- js实现ASP分页函数 HTML分页函数
- 设置SQLServer数据库中某些表为只读的多种方法分享
- jquery插件EasyUI中form表单提交实例分享
- 在android中增加curl的解决方法
- systemd添加自定义系统服务设置自定义开机启动的方法
- 如何使用VC库函数中的快速排序函数
- PHP4实际应用经验篇(8)
- Android 实用工具之emulator介绍
- java web response提供文件下载功能的实例讲解