PHP | DOMDocument createProcessingInstruction() Function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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();
  
?>

chevron_right


Output:

<?xml version="1.0" encoding="iso-8859-1"?>
<?name GeeksforGeeks?>

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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();
  
?>

chevron_right


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




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.