title: Convert a (nested)HTML unordered list of links to PHP array of links
body: <p>I have a regular, nested HTML unordered list of links, and I'd like to scrape it with PHP and convert it to an array. </p>
  
  <p>The original list looks something like this:</p>
  
  <pre><code>&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://someurl.com"&gt;First item&lt;/a&gt;
      &lt;ul&gt;
      &lt;li&gt;&lt;a href="http://someotherurl.com/"&gt;Child of First Item&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="http://someotherurl.com/"&gt;Second Child of First Item&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href="http://bogusurl.com"&gt;Second item&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="http://bogusurl.com"&gt;Third item&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="http://bogusurl.com"&gt;Fourth item&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Any of the items can have children. </p>
  
  <p>(The actual screen scraping is not a problem, I can do that.)</p>
  
  <p>I'd like to turn this into a PHP array, of just the links, while keeping the hierarchical nature of the list. Any ideas?</p>
  
  <p>I've looked at using htmlsimpledom and phpQuery, which both use jQuery like syntax. But, I can't seem to get the syntax right. I can get all the links, but I end up losing the hierarchical nature and order.</p>
  
  <p>Thanks.</p>