How can I iterate all tag and check if class is font18 or font17?
$html = new DOMDocument();
$html->load('file.html');
html:
<p><a name="bookmark7"></a><span class="font18" style="font-weight:bold;">Abilitazione</span></p>
<p><span class="font17">I medici devono essere autorizzati dallo Stato a praticare la loro professione. I requisiti per ottenere questa autorizzazione variano a seconda delle diverse Nazioni. I laureati presso Facoltà mediche estere possono ottenere l'autorizzazione a esercitare in Italia se rispondono ai requisiti statali per quanto riguarda il tirocinio e se superano l'esame di Stato. Nell'ambito della CEE si tratta tuttora di una questione da definire nei particolari.</span></p>
Thanks a lot.
Your HTML would give error of Input is not proper UTF-8, indicate encoding ! Bytes: 0xE0 0x20 0x6D 0x65 if you use $doc->load("file.html"); here is a simple work around
$doc = new DOMDocument('1.0', 'UTF-8');
libxml_use_internal_errors(true);
$doc->loadHTML(file_get_contents("file.html"));
foreach ( $doc->getElementsByTagName('span') as $node ) {
if (preg_match("/^font1[7|8]$/", $node->getAttribute('class'))) {
echo $node->nodeValue, "<br /><br />";
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With