DOMDocument::createCDATASection()函數是PHP中的內置函數,用於創建DOMCDATASection類的新實例。
用法:
DOMCDATASection DOMDocument::createCDATASection( string $data )
參數:該函數接受單個參數$data,該參數保存cdata的內容。
返回值:如果成功,此函數將返回新的DOMCDATASection;如果失敗,則返回FALSE。
以下示例程序旨在說明PHP中的DOMDocument::createCDATASection()函數:
程序1:
<?php
// Create a new DOMDocument
$domDocument = new DOMDocument('1.0', 'iso-8859-1');
// Use createCDATASection() function to create a new cdata node
$domElement = $domDocument->createCDATASection('GeeksforGeeks');
// Append element in the document
$domDocument->appendChild($domElement);
// Save the XML file and display it
echo $domDocument->saveXML();
?>
輸出:
<?xml version="1.0" encoding="iso-8859-1"?> <![CDATA[GeeksforGeeks]]>
程序2:
<?php
// Create a new DOMDocument
$domDocument = new DOMDocument('1.0', 'iso-8859-1');
// Use createComment() function to create a new comment node
$domComment = $domDocument->createComment('Create CDATA file');
// Use createCDATASection() function to create a new cdata node
$domElement = $domDocument->createCDATASection('GeeksforGeeks');
// Append element to the document
$domDocument->appendChild($domComment);
$domDocument->appendChild($domElement);
// Save the XML file and display it
echo $domDocument->saveXML();
?>
輸出:
<?xml version="1.0" encoding="iso-8859-1"?> <!--Create CDATA file--> <![CDATA[GeeksforGeeks]]>
參考: https://www.php.net/manual/en/domdocument.createcdatasection.php
相關用法
- PHP DOMDocument createElement()用法及代碼示例
- PHP DOMDocument createAttribute()用法及代碼示例
- PHP DOMDocument createElementNS()用法及代碼示例
- PHP DOMDocument createAttributeNS()用法及代碼示例
- PHP DOMDocument __construct()用法及代碼示例
- PHP DOMDocument load()用法及代碼示例
- PHP DOMDocument getElementsByTagName()用法及代碼示例
- PHP DOMDocument createComment()用法及代碼示例
- PHP DOMDocument createTextNode()用法及代碼示例
- PHP DOMDocument saveHTML()用法及代碼示例
- PHP DOMDocument createProcessingInstruction()用法及代碼示例
- PHP DOMDocument saveXML()用法及代碼示例
- PHP DOMDocument importNode()用法及代碼示例
- PHP DOMDocument createEntityReference()用法及代碼示例
- PHP DOMDocument save()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | DOMDocument createCDATASection() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。