recursion problems
<p>I'm grabbing links from a website, but I'm having a problem in which the higher I set the recursion depth for the function the results become stranger </p>

<p>for example 
when I set the function to the following </p>

<pre><code>crawl_page("http://www.mangastream.com/", 10);
</code></pre>

<p>I will get a results like this for about half the page </p>

<p><strong>http://mangastream.com/read/naruto/51619850/1/read/naruto/51619850/2/read/naruto/51619850/2/read/naruto/51619850/2/read/naruto/51619850/2/read/naruto/51619850/2/read/naruto/51619850/2/read/naruto/51619850/2</strong></p>

<p>EDIT </p>

<p>while I'm expecting results like this instead </p>

<p><strong>http://mangastream.com/manga/read/naruto/51619850/1</strong></p>

<p>here's the function I've been using to get the results </p>

<pre><code>function crawl_page($url, $depth)
{
    static $seen = array();
    if (isset($seen[$url]) || $depth === 0) {
        return;
    }
    $seen[$url] = true;

    $dom = new DOMDocument('1.0');
    @$dom-&gt;loadHTMLFile($url);

    $anchors = $dom-&gt;getElementsByTagName('a');
    foreach ($anchors as $element) {
        $href = $element-&gt;getAttribute('href');
        if (0 !== strpos($href, 'http')) {
            $href = rtrim($url, '/') . '/' . ltrim($href, '/');
        }
         if(shouldScrape($href)==true)   
          crawl_page($href, $depth - 1);
    }
    echo $url,"\r";
//,pageStatus($url)
}
</code></pre>

<p>any help with this would be greatly appreciated </p>
