title: PHP DOM: parsing a HTML list into an array?
body: <p>I have the below HTML string, and I would like to turn it into an array.</p>
  
  <pre><code>$string = '
  &lt;a href="#" class="something"&gt;1&lt;/a&gt;
  &lt;a href="#" class="something"&gt;2&lt;/a&gt;
  &lt;a href="#" class="something"&gt;3&lt;/a&gt;
  &lt;a href="#" class="something"&gt;4&lt;/a&gt;
  ';
  </code></pre>
  
  <p>Here's my current code with <code>DOMDocument</code>:</p>
  
  <pre><code>$dom = new DOMDocument;
  $dom-&gt;loadHTML($string);
  foreach( $dom-&gt;getElementsByTagName('a') as $node)
  {
      $array[] = $node-&gt;nodeValue; 
  }
  
  print_r($array);
  </code></pre>
  
  <p>However, this gives the below output:</p>
  
  <pre><code>Array ( [0] =&gt; 1 [1] =&gt; 2 [2] =&gt; 2 [3] =&gt; 4)
  </code></pre>
  
  <p>But I am looking for this result:</p>
  
  <pre><code>Array ( 
  [0] =&gt; &lt;a href="#" class="something"&gt;1&lt;/a&gt;
  [1] =&gt; &lt;a href="#" class="something"&gt;2&lt;/a&gt; 
  [2] =&gt; &lt;a href="#" class="something"&gt;3&lt;/a&gt;
  [3] =&gt; &lt;a href="#" class="something"&gt;4&lt;/a&gt;
  )
  </code></pre>
  
  <p>Is this possible?</p>