Functia
innerHTML() prezentata aici este echivalentul la proprietatea
innerHTML din JavaScript. Aceasta functie poate fi utilizata in PHP pentru a prelua continutul HTML dintr-un element HTML din obiect DOMDocument.
Cod functie innerHTML()
// returneaza un sir cu continutul HTML dintr-un element din DOMDocument ($elm)
function innerHTML(DOMNode $elm) {
$innerHTML = '';
$children = $elm->childNodes;
foreach($children as $child) {
$innerHTML .= $elm->ownerDocument->saveHTML($child);
}
return $innerHTML;
}
- Exemplu utilizare innerHTML().
<?php
// returneaza un sir cu continutul HTML dintr-un element din DOMDocument ($elm)
function innerHTML(DOMNode $elm) {
$innerHTML = '';
$children = $elm->childNodes;
foreach($children as $child) {
$innerHTML .= $elm->ownerDocument->saveHTML($child);
}
return $innerHTML;
}
// sir cu continut HTML
$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>';
// creaza obiect DOMDocument si incarca in el codul HTML din $strhtml
$dochtml = new DOMDocument();
$dochtml->loadHTML($strhtml);
// preia elementul cu id="dv2"
$dv2 = $dochtml->getElementById('dv2');
// foloseste innerHTML() pt a prelua continutul HTML din $dv2
$cnt_dv2 = innerHTML($dv2);
// afiseaza continutul HTML obtinut
echo $cnt_dv2;
?>
- Rezultat:
<p class="cls">Free PHP Course: <a href="https://coursesweb.net/php-mysql/" title="PHP Course">CoursesWeb.net</a></p>
Un Test simplu in fiecare zi
HTML
CSS
JavaScript
PHP-MySQL
Engleza
Spaniola
Ce tag adauga imagine in pagina web?
<div> <img> <span><img src="http://coursesweb.net/imgs/webcourses.gif" width="191" height="63" alt="Courses-Web" />
Care din aceste coduri CSS afiseaza textul inclinat?
font-style: italic; text-decoration: underline; font-weight: 500;#id {
font-style: italic;
}
Clic pe functia jQuery care ascunde animat un element HTML.
click() hide() show()$(document).ready(function() {
$(".a_class").click(function(){ $(this).hide("slow"); });
});
Clic pe functia definita corect in PHP.
fname function() {} function fname() {} function $fname() {};function fname($a, $b) {
echo $a * $b;
}
Indicati forma pentru Prezent Perfect Continuu a verbului "to walk" (a merge).
have walked have been walking be walkingI have been walking for 5 hours.
- Merg pe jos de 5 ore.
Indicati Trecutul Nedefinit pentru verbul "ser" (a fi) la forma Yo.
será sería fuiYo fui entrenador.
- Am fost antrenor.