Click here to Skip to main content
16,016,738 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello! i have regular expression:

PHP
return preg_replace("/(http|ftp|https):\/\/([^\s]+)/", "<a target=\"_blank\" href=\"http://$2\">$2</a>",$str);


I want that text link will be not longer that 50 symbols

For example: http://goo...

How tomodify this expression? Thank you! Its a very hard for me now
Posted

1 solution

You don't need regular expression for that:

PHP
function makelink($url, $limit=50){
  $text = strlen($url) > $limit ? substr($url, 0, $limit).'...' : $url;
  return "<a href='$url' target='_blank'>$text</a>";
}

echo makelink("http:\\www.google.com", 10);
 
Share this answer
 
Comments
Maciej Los 23-May-13 15:43pm    
+5
Zoltán Zörgő 23-May-13 15:52pm    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900