title: Iterate DOM elements with phpQuery
body: <p>I'm fetching an external page via curl and storing it in a variable. Then I need to parse all the 'a' tags in the document and modify it. To do so I need to loop through each 'a' tag. My current code: </p>
  
  <pre><code>    &lt;?php
      require 'phpQuery/phpQuery/phpQuery.php';
      $url = $_GET['url'];
  
      $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/1.0");
          curl_setopt($ch, CURLOPT_HEADER, 0);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      $result= curl_exec ($ch);
      curl_close ($ch);
  
      $curlUrl = 'http://localhost:8888/curl2.php?url='.$url;
      $doc = phpQuery::newDocument ($result);
  
  
  
      //loop here 
      $href = $doc-&gt;find('a')-&gt;attr('href');      
      if (preg_match($url,$href))
      {
          //do something
      }       
      $doc-&gt;find('#nav li a')-&gt;attr('href', $curlUrl.$href);
      //end loop
  
  
      echo '&lt;base href="'.$_GET['url'].'"/&gt;';
      echo $doc;
      ?&gt;
  </code></pre>
  
  <p>In jquery there is the .each() function which does what I need and iterates through each 'a' tag. Is there something similar in phpquery or other php DOM methods to iterate through the document and modify each 'a' tag?</p>
  
  <p>Cheers</p>