URL yolunu dosya adı uzantısı hariç eşleştirir

Bu senaryo için en iyi düzenli ifade ne olurdu?

Bu URL verildi:

http://php.net/manual/en/function.preg-match.php

http://php.netve.php` arasındaki (ancak dahil olmayan) her şeyi seçme konusunda nasıl bir yol izlemeliyim?

/manual/en/function.preg-match

Bu bir Nginx yapılandırma dosyası içindir.

Çözüm

Bunun gibi:


if (preg_match('/(?
Yorumlar (2)

Bunu dene:

preg_match("/net(.*)\.php$/","http://php.net/manual/en/function.preg-match.php", $matches);
echo $matches[1];
// prints /manual/en/function.preg-match
Yorumlar (0)

Bu genel URL eşleştirmesi, bir URL'nin bölümlerini seçmenize olanak tanır:

if (preg_match('/\\b(?Phttps?|ftp):\/\/(?P[-A-Z0-9.]+)(?P\/[-A-Z0-9+&@#\/%=~_|!:,.;]*)?(?P<parameters>\\?[-A-Z0-9+&@#\/%=~_|!:,.;]*)?/i', $subject, $regs)) {
    $result = $regs['file'];
    //or you can append the $regs['parameters'] too
} else {
    $result = "";
}
Yorumlar (0)