PHP | DOMProcessingInstruction __construct() Function
The DOMProcessingInstruction::__construct() function is an inbuilt function in PHP which is used a new read-only DOMProcessingInstruction object. To create a writable node, use DOMDocument::createProcessingInstruction.
Syntax:
public DOMProcessingInstruction::__construct( string $name, string $value )
Parameters: This function accept two parameters as mentioned above and described below:
- $name: It specifies the tag name of the processing instruction.
- $value: It specifies the value of the processing instruction.
Below given programs illustrate the DOMProcessingInstruction::__construct() function in PHP:
Program 1: Press Ctrl+U to see the DOM
php
<?php
$dom = new DOMDocument();
$html = $dom ->appendChild( new DOMElement( 'html' ));
$body = $html ->appendChild( new DOMElement( 'body' ));
$pinode = new DOMProcessingInstruction( 'php' ,
'echo "GeeksforGeeks"; ' );
$body ->appendChild( $pinode );
echo $dom ->saveXML();
?>
|
Output:
Program 2: Press Ctrl+U to see the DOM element.
php
<?php
$dom = new DOMDocument();
$html = $dom ->appendChild( new DOMElement( 'html' ));
$body = $html ->appendChild( new DOMElement( 'body' ));
$pinode = new DOMProcessingInstruction( 'xml-stylesheet' ,
'type="text/xsl" href="base.xsl"' );
$body ->appendChild( $pinode );
echo $dom ->saveXML();
?>
|
Output:
Reference: https://www.php.net/manual/en/domprocessinginstruction.construct.php
Last Updated :
12 Dec, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...