Skip to content
Related Articles

Related Articles

PHP | DOMDocument createProcessingInstruction() Function
  • Last Updated : 27 Aug, 2019

The DOMDocument::createProcessingInstruction() function is an inbuilt function in PHP which is used to create a new instance of class DOMProcessingInstruction.

Syntax:

DOMProcessingInstruction DOMDocument::createProcessingInstruction( $target, $data )

Parameters: This function accepts two parameters as mentioned above and described below:

  • $target: This parameter holds the target of the processing instruction.
  • $data: This parameter holds the content of the processing instruction.

Return Value: This function returns the new DOMProcessingInstruction on success or FALSE on failure.

Below programs illustrate the DOMDocument::createProcessingInstruction() function in PHP:



Program 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();
  
?>
Output:
<?xml version="1.0" encoding="iso-8859-1"?>
<?name GeeksforGeeks?>

Program 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();
  
?>
Output:
<?xml version="1.0" encoding="iso-8859-1"?>
<?name GeeksforGeeks?>
<?contact Noida?>
<?email abc@geeksforgeeks.org?>

Reference: https://www.php.net/manual/en/domdocument.createprocessinginstruction.php

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :