2

Possible Duplicate:
PHP - cut a string after X characters

Is there a way to cut or trim a String based on a Specific Size.

Let say we have "Lorem Ipsum dolor" and we want to cut that String to fit exactly the width of 20 Px and add "..." to the end of the String.

As far i tried this : http://www.php.net/manual/en/function.imagettfbbox.php but hard to get result as a newbie at PHP .

Community
  • 1
  • 1
Rosmarine Popcorn
  • 10,761
  • 11
  • 59
  • 89
  • check this link .. it will solve your question http://stackoverflow.com/questions/3161816/php-cut-a-string-after-x-characters – TKV Dec 29 '11 at 08:07
  • @TijoKVarghese i was searching for something like that http://msdn.microsoft.com/en-us/library/69ye7hc8.aspx but just solved with that CSS Rule . – Rosmarine Popcorn Dec 29 '11 at 08:57

1 Answers1

6

I think you shouldn't do this with PHP. Because Number of characters you can have inside 20px is depend on the Case of letters (Upper / Lower), language of the text, font, etc...

So you better try CSS.

Ex: text-overflow: ellipsis;

mac
  • 42,153
  • 26
  • 121
  • 131
Prasad Rajapaksha
  • 6,118
  • 10
  • 36
  • 52