php - using str_replace before simple_html_dom -
i'm using simple html dom grab scapped data , it's been working well. however, 1 of source have doesn't have unique fields i'm trying str_replace , grab elements i've renamed , use simple_html_dom.
however, doesn't work. code is:
require('simple_html_dom.php'); // create dom url or file $html = file_get_html('http://www.url.com'); $html = str_replace('<strong>','',$html); $html = str_replace('</strong>','',$html); $html = str_replace('<span class="pound">£</span>','',$html); $html = str_replace('<td>','<td class="myclass">',$html); foreach($html->find('td.myclass') $element) $price = $element->innertext; $price = preg_replace('/[^(\x20-\x7f)]*/','', $price); echo $price;
try
<?php require('simple_html_dom.php'); // create dom url or file $html = file_get_html( 'http://www.url.com' ); foreach( $html->find( 'td' ) $element ) { $price = trim( str_replace( "£", "", $element->plaintext ) ); } $price = preg_replace('/[^(\x20-\x7f)]*/','', $price); echo $price; ?>
Comments
Post a Comment