Eyl 04
Bir arkadaşın ihtiyacı için bulup buluşturduğum bir kod parçası
Kullanılan regexp cümleciği
1 | @(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@ |
Örnek kod
1 2 3 4 5 6 | $string='deneme olarak http://sayfa.site.com/goster/icerik.html bu linki ve http://sayfa.site.com/sakla/icerik.html sadece yazı içinden alıp link yapacak.'; $string = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $string); |
Örnek kodun çıktısı
1 2 3 | deneme olarak <a href="http://sayfa.site.com/goster/icerik.html">http://sayfa.site.com/goster/icerik.html</a> bu linki ve <a href="http://sayfa.site.com/sakla/icerik.html">http://sayfa.site.com/sakla/icerik.html</a> sadece yazı içinden alıp link yapacak. |
Son Yorumlar