title: Walking thru HTML in PHP
body: <p>Here is what I have so far:</p>
  
  <p>My string:</p>
  
  <pre><code>$str = "&lt;ul&gt;
  &lt;li&gt;&lt;a name="valuehere1" title="titlehere" href="/channel/london/"&gt;Link1&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a name="valuehere2" title="titlehere" href="/channel/games/"&gt;Link1&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a name="valuehere3" title="titlehere" href="/channel/sport/"&gt;Link1&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;";
  </code></pre>
  
  <p>My PHP so far (and I am stuck):</p>
  
  <pre><code>$dom = new domDocument;
  $dom-&gt;loadHTML($str);
  $children = $dom-&gt;getElementsByTagName('li')-&gt;item(0)-&gt;childNodes-&gt;getAttribute('name'); 
  $out = array();
  foreach ($children as $child) {
      $out[] = $dom-&gt;saveXML($child);
  }
  </code></pre>
  
  <p>I am trying to extract the NAME attribute value of the A tag in the LI base on a match (in this example they are "london", "games", "sport") . WHen I pass "games" it should give me the output as "valuehere2". This has to be done at the server side due to some restrictions I have. Can someone help me with this please?</p>
  
  <p>Thanks,
  L</p>