I know this is simple enough, but I need something a little more; I need to detect whether a url has a certain character length and if so to abbreviate the link text. I'm finding this a real struggle 🙁 I've tried various things but to no result. This is my current code that exchanges urls for links:

	$out = $text;
	$out=eregi_replace("^[url]ftp://[/url]([^ ,\r\n]*)","[url]ftp://\\1[/url]",$out);
	$out=eregi_replace("([ \r\n])[url]http://[/url]([^ ,\r\n]*)","\\1[url]http://\\2[/url]",$out);
	$out=eregi_replace("([ \r\n])[url]https://[/url]([^ ,\r\n]*)","\\1[url]https://\\2[/url]",$out);
	$out=eregi_replace("([ \r\n])[url]ftp://[/url]([^ ,\r\n]*)","\\1[url]ftp://\\2[/url]",$out);
	$out=eregi_replace("([ \r\n])[url]www.[/url]([^ ,\r\n]*)","\\1[url]http://www.\\2[/url]",$out);
	$out=eregi_replace("^[url]http://[/url]([^ ,\r\n]*)","[url]http://\\1[/url]",$out);
	$out=eregi_replace("^[url]https://[/url]([^ ,\r\n]*)","[url]https://\\1[/url]",$out);
	$out=eregi_replace("^[url]www.[/url]([^ ,\r\n]*)","[url]http://www.\\1[/url]",$out);

	$out=eregi_replace("\\[url\\]www.([^\\[]*)\\[img\\]www.([^\\[]*)\\[/img\\]\\[/url\\]","<a href=\"http://www.\\1\" target=_blank><img src=\"http://www.\\2\" border=\"0\"></a>",$out);
	$out=eregi_replace("\\[url\\]http://([^\\[]*)\\[img\\]http://([^\\[]*)\\[/img\\]\\[/url\\]","<a href=\"http://\\1\" target=_blank><img src=\"http://\\2\" border=\"0\"></a>",$out);
	$out=eregi_replace("\\[url\\]www.([^\\[]*)\\[/url\\]","<a href=\"http://www.\\1\" target=_blank>\\1</a>",$out);

	$out=eregi_replace("\\[url\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=_blank>"."\\1"."</a>",$out);
	//$out=eregi_replace("\\[url\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=_blank>\\1</a>",$out);
	$out=eregi_replace("\\[url=\&quot;","[url=\"",$out);
	$out=eregi_replace("\\&quot;\\]","\"]",$out);
	$out=eregi_replace("\\[url=([^\\[]*)\\]([^\\[]*)\\[\\/url\\]","<a href=\"\\1\" target=\"_blank\">\\2</a>",$out);
	$out=eregi_replace("\\[email\\]([^\\[]*)\\[/email\\]","<a href=\"mailto:\\1\">\\1</a>",$out);

If anyone could help me out, it would be very much appreciated!!!

thanks 🙂)

    Wow! That's a lot of code to do something that simple! I'm not going to read through it all but you do know about the strlen () function, right? It tells you the length of a string. Does that help?

      yes I know it, no it doesn't help.

        a year later

        does this help you? that's the function I use to auto convert URLs in forms.

        // make url clickable
        function make_clickable($input)
        {
        	$ret = " " . $input;
        	$ret = preg_replace("#([\n ])([a-z]+?)://([^, \n\r]+)#i", "\\1<a href=\"\\2://\\3\" target=\"_blank\" class=\"SmallLinks\">\\2://\\3</a>", $ret);
        	$ret = preg_replace("#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[^, \n\r]*)?)#i", "\\1<a href=\"http://www.\\2.\\3\\4\" target=\"_blank\" class=\"SmallLinks\">[url]www.\\2.\\3\\4[/url]</a>", $ret);
        	$ret = eregi_replace("([-a-z0-9_]+(\.[_a-z0-9-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)+))","<A HREF=\"mailto:\\1\" class=\"SmallLinks\">\\1</A>",$ret);
        	$ret = substr($ret, 1);
        	return($ret);
        }
        
          Write a Reply...