title: How to parse html to get values in array using php
body: <p>So I'm trying to parse data using JS. Here is the HTML code which I have. There are more than 10000 records to parse. Just mentioning a few for clarification:</p>
  <pre><code> $str = '&lt;ul&gt;
         &lt;li&gt;
            &lt;a href=&quot;https://www.example.com/profile/shrey&quot;&gt;Shrey Chathly&lt;/a&gt;
            &lt;p&gt; shrey@yahoo.com&lt;/p&gt;
            &lt;p&gt; 9910212121&lt;/p&gt;
         &lt;/li&gt;
         &lt;li&gt;
            &lt;a href=&quot;https://www.example.com/profile/neminath&quot;&gt;Neminath&lt;/a&gt;
            &lt;p&gt; 9818505051&lt;/p&gt;
         &lt;/li&gt;
         &lt;li&gt;
            &lt;a href=&quot;https://www.example.com/profile/mohan&quot;&gt;Mohan&lt;/a&gt;
            &lt;p&gt; Mohan@yahoo.co.in&lt;/p&gt;
            &lt;p&gt; 9111502287&lt;/p&gt;
         &lt;/li&gt;
         &lt;li&gt;
            &lt;a href=&quot;https://www.example.com/profile/naina&quot;&gt;Naina&lt;/a&gt;
            &lt;p&gt; naina@gmail.com&lt;/p&gt;
            &lt;p&gt; 9818505001&lt;/p&gt;
         &lt;/li&gt;
         &lt;li&gt;
            &lt;a href=&quot;https://www.example.com/profile/mohan&quot;&gt;Rakesh&lt;/a&gt;
            &lt;p&gt; 9111502222&lt;/p&gt;
         &lt;/li&gt;
      &lt;/ul&gt;';
  </code></pre>
  <p>I have tried to do that with:</p>
  <pre><code>$dom = new DOMDocument();
  $dom-&gt;loadHTML($str);
  $a = $dom-&gt;getElementsByTagName('a'); //DOMNodeList
  $p = $dom-&gt;getElementsByTagName('p'); //DOMNodeList
  
  foreach($a as $NodeHeader){
    $aDataTableHeaderHTML[] = trim($NodeHeader-&gt;textContent);
  }
  
  $i = 0;
  $j = 0;
  foreach($p as $sNodeDetail) {
    $aDataTableDetailHTML[$j][] = trim($sNodeDetail-&gt;textContent);
    $i = $i + 1;
    $j = $i % count($aDataTableHeaderHTML) == 0 ? $j + 1 : $j;      
  
  
   }
  
    //print_r($aDataTableDetailHTML);
    // out put
          Array
          (
              [0] =&gt; Array
                  (
                      [0] =&gt; shrey@yahoo.com
                      [1] =&gt; 9910212121
                      [2] =&gt; 9818505051
                      [3] =&gt; Mohan@yahoo.co.in
                      [4] =&gt; 9111502287
                  )
              [1] =&gt; Array
                  (
                      [0] =&gt; naina@gmail.com
                      [1] =&gt; 9818505001
                      [2] =&gt; 9111502222
                  )
          )
  </code></pre>
  <p>I want output like :</p>
  <pre><code>Array
      (
          [0] =&gt; Array
              (
                  [0] =&gt; Shrey Chathly
                  [1] =&gt; shrey@yahoo.com
                  [2] =&gt; 9910212121
              )
          [1] =&gt; Array
              (
                  [0] =&gt; Neminath
                  [1] =&gt; 
                  [2] =&gt; 9818505051
              )
           [2] =&gt; Array
              (
                  [0] =&gt; Mohan
                  [1] =&gt; mohan@yahoo.co.in
                  [2] =&gt; 9111502287
              ) 
            [3] =&gt; Array
              (
                  [0] =&gt; Naina
                  [1] =&gt; naina@gmail.com
                  [2] =&gt; 9818505001
              ) 
            [4] =&gt; Array
              (
                  [0] =&gt; Rakesh
                  [1] =&gt; 
                  [2] =&gt; 9111502222
              )      
      )
  </code></pre>
  <p>I'm not able to find a way to achieve the expected output.
  Please help me.  Many thanks in advance.</p>