php - Simple HTML DOM returning NULL -


i'm scraping data website using simple html dom parser (http://simplehtmldom.sourceforge.net/)

the html is:

<tr class="productlisting-odd">     <td align="right" class="productlisting-data">&nbsp;0&nbsp;</td>     <td class="productlisting-data">&nbsp;<a href="http://www.spellvault.net/p46563/liliana-of-the-veil/product_info.html" onmouseout="hd()" onmouseover="sd('images/101257121.jpg')">liliana of veil</a>&nbsp;<br>    </td>     <td align="center" class="productlisting-data">&nbsp;black&nbsp;</td>     <td align="center" class="productlisting-data">&nbsp;mythic&nbsp;</td>     <td align="center" class="productlisting-data">&nbsp;innistrad&nbsp;</td>     <td align="right" class="productlisting-data">€42,50&nbsp;</td>     <td align="center" class="productlisting-data"><input type="text" name="var[46563]" value="" size="4">&nbsp;    <span class="nowrap"><span class="template-button-left">&nbsp;</span><span class="template-button-middle"><input class="submitbutton" type="submit" value="bestel"></span><span class="template-button-right">&nbsp;</span></span>&nbsp;</td>   </tr> 

and php:

include_once('simple_html_dom.php');  $html = file_get_html('-the url of search query on website-');  $array = array(); foreach($html->find('.productlisting-odd, .productlisting-even') $element) {     $row = array(         'name' => strip_tags($element->childnodes(1)->innertext),         'set' => strip_tags($element->childnodes(4)->innertext),         'price' => strip_tags($element->childnodes(5)->innertext),         'stock' => strip_tags($element->childnodes(0)->innertext)     );     array_push($array, $row); } echo json_encode($array); 

for reason, value of 'price' keeps returning null. other values collected properly. can't figure out why happening, since elements seem have same structure.

thanks in advance!

most html parsed has non-unicode charset. , problem since json_encode() works utf-8 encoding. data parsed has ascii characters doesn't lead problem. price data (6th column) contains non-ascii character '€' on json_encode() fails (and return null).


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -