PHP DOMDocument createProcessingInstruction() Function
The DOMDocument::createProcessingInstruction() function is an inbuilt function in PHP that is used to create a new instance of the 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 examples illustrate the DOMDocument::createProcessingInstruction() function in PHP:
Example 1:
php
<?php
$domDocument = new DOMDocument( '1.0' , 'iso-8859-1' );
$domPI = $domDocument ->createProcessingInstruction( "name" , "GeeksforGeeks" );
$domDocument ->appendChild( $domPI );
echo $domDocument ->saveXML();
?>
|
Output:
<?xml version="1.0" encoding="iso-8859-1"?>
<?name GeeksforGeeks?>
Example 2:
php
<?php
$domDocument = new DOMDocument( '1.0' , 'iso-8859-1' );
$domPI1 = $domDocument ->createProcessingInstruction( "name" ,
"GeeksforGeeks" );
$domPI2 = $domDocument ->createProcessingInstruction( "contact" ,
"Noida" );
$domPI3 = $domDocument ->createProcessingInstruction( "email" ,
"abc@geeksforgeeks.org" );
$domDocument ->appendChild( $domPI1 );
$domDocument ->appendChild( $domPI2 );
$domDocument ->appendChild( $domPI3 );
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
Last Updated :
03 Apr, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...