Şimdi Ara!

Girişimzel Reklam

18 Şubat 2017 Cumartesi

PHP otomatik link fonksiyonu

Herhangi bir linki algılayabilen fonksiyondur.

function auto_link($text) {
    $pattern = '/(((http[s]?:\/\/(.+(:.+)?@)?)|(www\.))[a-z0-9](([-a-z0-9]+\.)*\.[a-z]{2,})?\/?[a-z0-9.,_\/~#&=:;%+!?-]+)/is';
    $text = preg_replace($pattern, ' $1', $text);
    // fix URLs without protocols
    $text = preg_replace('/href="www/', 'href="http://www', $text);
    return $text;
}

Hiç yorum yok:

Yorum Gönder