Hello! I am trying to remove any html tags which are taken using PHP Simple HTML DOM. I am using this link from ebay.com: shorturl.at/jtUX4. Until now I only managed to get rid of the attributes` content and not the actual tags and css classes. Here is my code:
$description = $html->find("iframe[id=desc_ifr]", 0);
//var_dump($description);
if($description != null){
$source = $description->src;
//var_dump($source);
//$item['description']=$dom->saveHTML($source);
//$lines_string=file_get_contents($source)
if(isset($source)){
$descrHtml = getWebPage($source);
unset($source);
$descrDom = new simple_html_dom();
$descrDom->load($descrHtml);
foreach ($descrDom->find("#ds_div") as $key => $div) {
$descr = $div->innertext;
$cleandescr = preg_replace('/<[^>]*>/', '', $descr);
$cleandescription = trim(preg_replace('/\s+/',' ', $cleandescr));
//var_dump($cleandescription);
$cleandescription1 = str_replace('img{max-width:100%}', '', $cleandescription);
$cleanedcss= preg_replace('~(?:\s*/\*.*?\*/\s*)|\{\K(?:\'[^\']*\'|"[^"]*"|/\*.*?\*/|(?:(?R)|[^}]))*~', '', $cleandescription1);
$cleanedclasses= str_replace('.center-page {} .push-left {} .qe td {} .qe .center {} .qe .label {} .qe .indent {} .qe .fit {} .limit-width {}', '', $cleanedcss);
$item['description'] = htmlspecialchars_decode(trim(str_replace(" ", "", $cleanedclasses)));
$item['description']=strip_tags($cleanedcss);
//var_dump($item['description']);
}
}
}else{
$item['description'] = '';
}
After debug I receive this result:
body {} h1 {} } h2, h3, h4, h5, h6 {} .navbar a, .navbar a:active, .navbar a:hover, .navbar a:visited {} .product-specs {} .product-specs td {} .attr-left {} .attr-right {} div.footer {} .navbar-default {} .navbar-default .navbar-nav > .active > a {}.col-md-6{} .col-md-12{} .container{} @media (min-width:768px){ .container{} .col-md-12, .col-md-6{} .col-md-6{} } @media (min-width:992px){ .container{} .col-md-12,.col-md-6{} .col-md-6{} } @media (min-width:1200px){ .container{} .col-md-12,.col-md-6{} .col-md-6{} } .img-responsive{}.nav{} .nav:before, .nav:after{} .nav:after{} .nav:before, .nav:after{} .nav:after{} .nav > li{} .nav > li > a{} .nav > li > a:hover, .nav > li > a:focus{} .nav > li > a > img{} .navbar{} @media (min-width:768px){.navbar{} } .navbar-header:before, .navbar-header:after{} .navbar-header:after{} .navbar-header:before, .navbar-header:after{} .navbar-header:after{} @media (min-width:768px){.navbar-header