这篇文章主要讲解了“php在生成xml时怎么添加CDATA标签”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“php在生成xml时怎么添加CDATA标签”吧!
本文实例讲述了php生成xml时添加CDATA标签的方法。分享给大家供大家参考。具体实现方法如下:
其实php生成xml时添加CDATA标签方法非常的简单,因为是一个在xml中可以存储各种内容的标签了,下面整理了一个例子希望对各位有帮助。
有码有真相,贴上代码,大家不要把<![CDATA[ $text]]>当成前后缀,其实它可以是标签。
具体代码如下:
<?php$dom = new DOMDocument("1.0");// display document in browser as plain text// for readability purposesheader("Content-Type: text/plain");// create root element$root = $dom->createElement("toppings");$dom->appendChild($root);// create child element$item = $dom->createElement("item");$root->appendChild($item);// create text node$text = $dom->createTextNode("pepperoni");$item->appendChild($text);// create attribute node$price = $dom->createAttribute("price");$item->appendChild($price);// create attribute value node$priceValue = $dom->createTextNode("4");$price->appendChild($priceValue);// create CDATA section$cdata = $dom->createCDATASection(" Customer requests that pizza be sliced into 16 square pieces ");$root->appendChild($cdata);// create PI$pi = $dom->createProcessingInstruction("pizza", "bake()");$root->appendChild($pi);// save and display treeecho $dom->saveXML();?>
感谢各位的阅读,以上就是“php在生成xml时怎么添加CDATA标签”的内容了,经过本文的学习后,相信大家对php在生成xml时怎么添加CDATA标签这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联网站建设公司,,小编将为大家推送更多相关知识点的文章,欢迎关注!
当前名称:php在生成xml时怎么添加CDATA标签-创新互联
链接分享:https://www.cdcxhl.com/article4/dspsoe.html
成都网站建设公司_创新互联,为您提供做网站、外贸网站建设、网站策划、App开发、建站公司、网页设计公司
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联