Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand your problem correctly this is how you should do it.</p> <p>First of all I suggest you catch each row instead of individual cells and then parse each row independently.</p> <p>So in this example I assume that you row is wrapped in <code>tr</code> tags:</p> <pre><code>&lt;tr&gt; &lt;td&gt;&lt;a href="/subname/index.jsp"&gt;SubName&lt;/a&gt;&lt;/td&gt; &lt;!-- This is the name of the subscription --&gt; &lt;td&gt;Comment regarding the subscription&lt;/td&gt;&lt;!-- Comment --&gt; &lt;td&gt;&lt;strong&gt;0,-&lt;/strong&gt;&lt;/td&gt;&lt;!-- Monthly fee --&gt; &lt;td&gt;0,49&lt;/td&gt;&lt;!-- Price per minute --&gt; &lt;td&gt;0,49&lt;/td&gt;&lt;!-- Price per SMS --&gt; &lt;td&gt;1,99&lt;/td&gt;&lt;!-- Price per MMS --&gt; &lt;/tr&gt; </code></pre> <p>If there are more cells at the beginning or the end you will just have to adjust indexes accordingly. Also I havent tested this code so there might be some errors there but the general idea should be ok.</p> <pre><code>//here we will store parsed values $data = array(); // you may want to filter this a bit if you want some rows to be skipped foreach ($html-&gt;find('tr') as $tr) { // we get first cell in the row, find a element inside and take it's inner text and so on $name = $tr-&gt;children(1)-&gt;find('a')-&gt;innertext; $comment = $tr-&gt;children(2)-&gt;innertext; $monthyFee = $tr-&gt;children(3)-&gt;find('strong')-&gt;innertext; $pricePerMin = $tr-&gt;children(4)-&gt;innertext; $pricePerSms = $tr-&gt;children(5)-&gt;innertext; $pricePerMms = $tr-&gt;children(6)-&gt;innertext; // create new entry in $data array formatted as you wanted it $data[$name] = array($comment, $monthlyFee, $pricePerMin, $pricePerSms, $pricePerMms); } </code></pre> <p>Important note here - this won't prevent you from overwriting some data in case your name is not unique so you must be sure if it really is. This is because associative arrays cannot have multiple keys with the same value.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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