I’m using the Facebook API to display posts on a web page from a particular Facebook account. When the Facebook user posts a message that contains a link with long URL text (i.e. < a href=”http://www.google.com”>http://thisisreallylongandeventuallybreaksmyfrigginlayout < / a >), it’s breaking my layout.
Here’s the PHP function I’m currently using to take the post from the Facebook API and turn any URLs into HTML links:
public function linkify($ret) {
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\">\\2</a>", $ret);
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\">\\2</a>", $ret);
$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
return $ret;
}
Can anyone help me to change the function so that it also truncates any long link text? I’m not talking about truncating the entire message, just any long text for links.
Thanks!
Got it to work by adding this line to my function: