DOMDocument::createProcessingInstruction()函數是PHP中的內置函數,用於創建DOMProcessingInstruction類的新實例。
用法:
DOMProcessingInstruction DOMDocument::createProcessingInstruction( $target, $data )
參數:該函數接受上述和以下描述的兩個參數:
- $target:此參數保存處理指令的目標。
- $data:此參數保存處理指令的內容。
返回值:如果成功,此函數返回新的DOMProcessingInstruction;如果失敗,則返回FALSE。
以下示例程序旨在說明PHP中的DOMDocument::createProcessingInstruction()函數:
示例1:
<?php
// Create a new DOMDocument
$domDocument = new DOMDocument('1.0', 'iso-8859-1');
// Use createProcessingInstruction() function to create
// a new Processing Instruction node
$domPI = $domDocument->createProcessingInstruction("name", "GeeksforGeeks");
// Append element to the document
$domDocument->appendChild($domPI);
// Create XML document and display it
echo $domDocument->saveXML();
?>
輸出:
<?xml version="1.0" encoding="iso-8859-1"?> <?name GeeksforGeeks?>
示例2:
<?php
// Create a new DOMDocument
$domDocument = new DOMDocument('1.0', 'iso-8859-1');
// Use createProcessingInstruction() function to create
// a new Processing Instruction node
$domPI1 = $domDocument->createProcessingInstruction("name",
"GeeksforGeeks");
$domPI2 = $domDocument->createProcessingInstruction("contact",
"Noida");
$domPI3 = $domDocument->createProcessingInstruction("email",
"abc@geeksforgeeks.org");
// Append element to the document
$domDocument->appendChild($domPI1);
$domDocument->appendChild($domPI2);
$domDocument->appendChild($domPI3);
// Create XML document ans display it
echo $domDocument->saveXML();
?>
輸出:
<?xml version="1.0" encoding="iso-8859-1"?> <?name GeeksforGeeks?> <?contact Noida?> <?email abc@geeksforgeeks.org?>
參考: https://www.php.net/manual/en/domdocument.createprocessinginstruction.php
相關用法
- PHP DOMDocument createAttribute()用法及代碼示例
- PHP DOMDocument __construct()用法及代碼示例
- PHP DOMDocument createAttributeNS()用法及代碼示例
- PHP DOMDocument createComment()用法及代碼示例
- PHP DOMDocument normalizeDocument()用法及代碼示例
- PHP DOMDocument loadXML()用法及代碼示例
- PHP DOMDocument loadHTMLFile()用法及代碼示例
- PHP DOMDocument createElementNS()用法及代碼示例
- PHP DOMDocument createCDATASection()用法及代碼示例
- PHP DOMDocument load()用法及代碼示例
- PHP DOMDocument loadHTML()用法及代碼示例
- PHP DOMDocument createElement()用法及代碼示例
- PHP DOMDocument createEntityReference()用法及代碼示例
- PHP DOMDocument saveXML()用法及代碼示例
- PHP DOMDocument importNode()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | DOMDocument createProcessingInstruction() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。