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("https://phpkodlari.com/php");

preg_match_all("/href=\"([^\"]+)/i",$sayfa,$matches);
       
foreach ($matches[0] as $tek)
{
    echo $tek ."<br>";
}

Sonuç:

href="https://phpkodlari.com/php/urlencode
href="https://phpkodlari.com/php/
href="https://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
2009-11-28 14:56:40

phpkodlari.com © 2009 Herkes Php öğrenecek
Eglence ve Oyun: Gamikro