Hi all
I have the following code which does a reasonable job of finding various styles of links within text (eg or just and turning them into links.
My problem is if someone enters a really long link I'd like to truncate what actually shows on screen, eg " would still link there but show as just " etc
I've tried to do stuff but failed - I certainly don't seem able to tamper with the preg stuff eg "substring('$1$2$3$4',0,50)" doesn't work.
Can anyone shed light on what I thought would be a common thing to want to do (yet lots of people search/post online for how to do it?)
I also need to achieve the same thing with my javascript version ...
_________________________________
Leozack
I have the following code which does a reasonable job of finding various styles of links within text (eg or just and turning them into links.
PHP:
function linkURLs($text) {
$text = str_replace("/","/",$text);
return preg_replace('@(http)?(s)?(://)?(([-\w]+\.)+([^\s]+)+[^,.\s])@', '<a href="http$2://$4">$1$2$3$4</a>', $text);
$text = str_replace("/","/",$text); // think this line is redundant now
}
I've tried to do stuff but failed - I certainly don't seem able to tamper with the preg stuff eg "substring('$1$2$3$4',0,50)" doesn't work.
Can anyone shed light on what I thought would be a common thing to want to do (yet lots of people search/post online for how to do it?)
I also need to achieve the same thing with my javascript version ...
JavaScript:
function LinkURLs(text) {
text.replace('/','/');
var exp = /((?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/ig
return text.replace(exp,"<a href='$1'>$1</a>");
}
_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);