當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP DOMDocument createProcessingInstruction()用法及代碼示例


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



相關用法


注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | DOMDocument createProcessingInstruction() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。