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 writeable 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

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new DOMDocument instance
$dom = new DOMDocument();
  
// Create a html element
$html = $dom->appendChild(new DOMElement('html'));
  
// Create a body element
$body = $html->appendChild(new DOMElement('body'));
  
// Create a new DOMProcessingInstruction node
$pinode = new DOMProcessingInstruction('php',
          'echo "GeeksforGeeks"; ');
  
// Append the child
$body->appendChild($pinode);
  
// Render the XML
echo $dom->saveXML();
?>

chevron_right


Output:

Program 2: Press Ctrl+U to see the DOM element.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new DOMDocument instance
$dom = new DOMDocument();
  
// Create a html element
$html = $dom->appendChild(new DOMElement('html'));
  
// Create a body element
$body = $html->appendChild(new DOMElement('body'));
  
// Create a new DOMProcessingInstruction node
$pinode = new DOMProcessingInstruction('xml-stylesheet',
       'type="text/xsl" href="base.xsl"');
  
// Append the child
$body->appendChild($pinode);
  
// Render the XML
echo $dom->saveXML();
?>

chevron_right


Output:

Reference: https://www.php.net/manual/en/domprocessinginstruction.construct.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.