Preg_Match_All
Bir yazı içinde regular expression kullanarak kelime aramaya yarar.
Örneğin: Bir internet sitesindeki tüm linkleri almak istiyoruz diyelim. bu durumda aşağıdaki gibi bir kod kullanabilirsiniz:
preg match All kullanmadan önce file_get_contents ile web sayfasını okutuyoruz.
$sayfa=file_get_contents("http://www.phpkodlari.com/php");
preg_match_all("/href=\"([^\"]+)/i",$sayfa,$matches);
foreach ($matches[0] as $tek)
{
echo $tek ."<br>";
}
preg_match_all("/href=\"([^\"]+)/i",$sayfa,$matches);
foreach ($matches[0] as $tek)
{
echo $tek ."<br>";
}
Sonuç:
href="http://www.phpkodlari.com/php/urlencode
href="http://www.phpkodlari.com/php/
href="http://www.phpkodlari.com/php-dersleri/
...
...
linklerin önündeki href kısmını silmek için str_replace komutunu kullanabilirsiniz.
Her programcı birgün Php yi tadacaktır
28-11-2009 14:56
Alakalı Konular: php ile sayfadan link toplamak
Benzer Konular:
www.Phpkodlari.com © 2009 Herkes Php öğrenecek
Web tasarım ve eğitim kaynağınız.