Monday, October 6, 2025
HomeLanguagesPHP | DOMProcessingInstruction __construct() Function

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
 
// 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 "neveropen"; ');
 
// Append the child
$body->appendChild($pinode);
 
// Render the XML
echo $dom->saveXML();
?>


Output: 
 

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

php




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


Output: 
 

Reference: https://www.php.net/manual/en/domprocessinginstruction.construct.php
 

RELATED ARTICLES

Most Popular

Dominic
32337 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6707 POSTS0 COMMENTS
Nicole Veronica
11871 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6823 POSTS0 COMMENTS
Ted Musemwa
7089 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6779 POSTS0 COMMENTS