Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's probably a bug in "ganon" of the html - if you take your example of html:</p> <pre><code>$html = '&lt;table&gt; &lt;tr class="last even"&gt; &lt;th class="label"&gt;SKU&lt;/th&gt; &lt;td class="data last"&gt;some sku here i want to get &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;'; $html = str_get_dom($html); </code></pre> <p>for some reason because of the new line in the html "ganon" thinks that the next element is a text element and only then there is the desire td - so you have to do this:</p> <pre><code> foreach ($html('th.label') as $elem){ if($elem-&gt;getPlainText()=='SKU'){ //elem -&gt; text node -&gt; td node echo($elem-&gt;getSibling(1)-&gt;getSibling(1)-&gt;getPlainText()); } } </code></pre> <p>If you organize your html like this (without new line):</p> <pre><code>$html = '&lt;table&gt; &lt;tr class="last even"&gt; &lt;th class="label"&gt;SKU&lt;/th&gt;&lt;td class="data last"&gt;some sku here i want to get &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;'; </code></pre> <p>Then your original code will work <code>$elem-&gt;getSibling(1)-&gt;getPlainText()</code></p> <p>Maybe consider using the <a href="http://simplehtmldom.sourceforge.net/" rel="nofollow">php simple html dom</a> class - it's much more intuitive, using full oop methods, jquery dom parser like and don't uses this awful var-function method :):</p> <pre><code>require('simple_html_dom.php'); $html = '&lt;table&gt; &lt;tr class="last even"&gt; &lt;th class="label"&gt;SKU&lt;/th&gt; &lt;td class="data last"&gt;some sku here i want to get &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;'; $dom = str_get_html($html); foreach($dom-&gt;find('th.label') as $el){ if($el-&gt;plaintext == 'SKU'){ echo($el-&gt;next_sibling()-&gt;plaintext); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload