Saturday, 14 September 2013

parsing HTML with native DomDocument instead of simple html parser

parsing HTML with native DomDocument instead of simple html parser

for the past months i was using Simple html Dom it's pretty easy and i
accustomed to but with big file sizes i am getting problem and slow
performance.
so i decided to use the native php DomDocument the problem now is that i
am not familiar with it and mean time have very tight schedule so i am
posting to get urgent help to convert my code to native domdocument
my current code with the simple html parser
<?php
foreach ($events->find('div.lshpanel') as $content) {
$url = 'http://www.domain.com/some-words-';
$url .= str_replace(' ', '-', $content->find('span.section',
0)->plaintext) . '_';
$url .= str_replace(array(' ', '/', '\\', ',', ':'), '-',
$content->find('span.category', 0)->plaintext) . '-';
$url .= str_replace(array(' ', '/', '\\', ',', ':'), '-',
$content->find('span.lshevent', 0)->plaintext) . '-';
$url .= filter_var($content->id, FILTER_SANITIZE_NUMBER_INT) . '.html';
$finalUrl = str_replace('_', '-', $url);
$finalUrl = preg_replace('!-+!', '-', $finalUrl);
//$finalUrl = $url;
$content->style = null;
$content->find('h3.lshjpane-toggler', 0)->onclick = null;
$el = $content->find('.category', 0);
$link = "<a class=\"openevent\" href=\"$finalUrl\"
target=\"_blank\">Open Event</a>";
$content->find('.category', 0)->innertext = $el->innertext . $link;
}
?>
i want to rewrite the same code but to work with domdocument really i am
on tight schedule any help appretiated.

No comments:

Post a Comment