Oj Obasi
Oj Obasi

I am also and will continue to be a student of web design and development. My tutorials may not be for you. If you feel that way, then search online for better tutorials.

How to make links clickable in block of text using php

We will be building a function that can read urls and make them clickable and open in a new tab with the option of adding a class to style your urls. This can be used even with text returning from the database.

function make_links_clickable($tutorial, $class='', $target='_blank'){
return preg_replace('!((http\:\/\/|ftp\:\/\/|https\:\/\/)|www\.)([-a-zA-Zа-яА-Я0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?!ism',
'<a class="'.$class.'" href="//$3" target="'.$target.'">$1$3</a>',
$tutorial);
}
$tutorial = make_links_clickable($tutorial, $class='', $target='_blank');

This can be use with ftp, http, ftps and https schemes.
Download the source code and check it out!