Php-mysql Course

The innerHTML() function presented in this page it is the equivalent of the innerHTML property from JavaScript. This function can be used in PHP to get the HTML content from a HTML element within a DOMDocument object.

Code of innerHTML()

// returns a string with the HTML content from a DOMDocument node element ($elm)
function innerHTML(DOMNode $elm) { 
  $innerHTML = ''; 
  $children  = $elm->childNodes;

  foreach($children as $child) { 
    $innerHTML .= $elm->ownerDocument->saveHTML($child);
  }

  return $innerHTML;
}
- Example usage of innerHTML().
<?php
// returns a string with the HTML content from a DOMDocument node element ($elm)
function innerHTML(DOMNode $elm) { 
  $innerHTML = ''; 
  $children  = $elm->childNodes;

  foreach($children as $child) { 
    $innerHTML .= $elm->ownerDocument->saveHTML($child);
  }

  return $innerHTML;
}

// string with HTML content
$strhtml = '<div id="dv1">Flash Games: https://marplo.net/jocuri/</div>
 <div id="dv2"><p class="cls">Free PHP Course: <a href="https://coursesweb.net/php-mysql/" title="PHP Course">CoursesWeb.net</a></p></div>';

// create the DOMDocument object, and load HTML from $strhtml
$dochtml = new DOMDocument();
$dochtml->loadHTML($strhtml);

// get the element with id="dv2"
$dv2 = $dochtml->getElementById('dv2');

// uses innerHTML() to get the HTML content from $dv2
$cnt_dv2 = innerHTML($dv2);

// output the HTML content
echo $cnt_dv2;
?>
- Output:
<p class="cls">Free PHP Course: <a href="https://coursesweb.net/php-mysql/" title="PHP Course">CoursesWeb.net</a></p>

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag defines the clickable areas inside the image map?
<map> <img> <area>
<img src="image.jpg" usemap="#map1">
<map name="map1">
  <area shape="rect" coords="9, 120, 56, 149" href="#">
  <area shape="rect" coords="100, 200, 156, 249" href="#">
</map>
Which CSS property defines what is done if the content in a box is too big for its defined space?
display overflow position
#id {
  overflow: auto;
}
Click on the event which is triggered when the mouse is positioned over an object.
onclick onmouseover onmouseout
document.getElementById("id").onmouseover = function(){
  document.write("Have Good Life");
}
Indicate the PHP variable that contains data added in URL address after the "?" character.
$_SESSION $_GET $_POST
if(isset($_GET["id"])) {
  echo $_GET["id"];
}
innerHTML in PHP

Last accessed pages

  1. Create simple Website with PHP (43819)
  2. PHP getElementById and getElementsByTagName (49136)
  3. JavaScript base64 encode decode (5827)
  4. The School for Gods (5771)
  5. 101 Zen stories (2003)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (240)
  2. Read Excel file data in PHP - PhpExcelReader (83)
  3. The Four Agreements (72)
  4. PHP Unzipper - Extract Zip, Rar Archives (72)
  5. The Mastery of Love (60)
Chat
Chat or leave a message for the other users
Full screenInchide