My function works without any problem with ftp, http and https
function makeClickableLinks($s) {
return preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Z?-??-?()0-9@:%_+.~#?&;//=]+)!i',
'<a href="$1">$1</a>', $s);
}
However, it doesnt make clickable if url is www.example.org (if there is no http)
If I replace the ((f|ht)tp(s)?://) to www , it works, however, if url has http, it makes clickable only after http part.
How can I make it work correctly both with http and without http ?
www.example.org, you'll have to fix it up intohttp://www.example.orgto begin with; justhref="www.example.org"either won't work as you expect or is invalid, depending on your definition. So, you'll need to produce a separate regex and replace for that, you cannot cram it into this regex.str_replace('a href="www.', 'a href="http://www.', $string);after your regex.