strpos sorun: değeri ublic döndü alıyorum

0 Cevap php

Ben bir web sayfası açın ve sayfadaki tüm giden bağlantıları href değerlerini depolamak için bir sınıf yapıyorum. Bu ilk 3 için çalışıyor nedense o garip gider. Aşağıda benim kodudur:

class Crawler {
var $url;

function construct($url) {
    $this->url = 'http://'.$url;
    $this->crawl();
}

function crawl() {
    $str = file_get_contents($this->url);
    $start = 0;
    for($i=0; $i<10; $i++) {
        $beg = strpos($str, '<a href="http://',$start)+16;
        $end = strpos($str,'"',$beg);
        $diff = $end - $beg;
        $links[$i] = substr($str,$beg, $diff);
        $start = $start + $beg;
    }
    print_r($links);
}
}

$crawler = new Crawler;
$crawler->construct('www.yahoo.com');

Ignore the for loop for the time being I know this will only return the first 10 and won't do the whole document. But if you run this code the first 3 work fine but then all the other values are UBLIC. Can anyone help? Thanks

0 Cevap