jurass1c Posted May 24, 2010 Share Posted May 24, 2010 I was wondering how to get "..." after the text i have cut using Substr. Here in an example of what i mean: Say i wanted cut down something like a Movie name. "Pulp Fiction" i use Substr to cut down the characters to only 7 so it would echo only "Pulp Fic" how would i go about adding "..." (3 dots) after Substr cuts off the name ? so it would look like this "Pulp Fic..." - (notice the 3 dots after the name) Its prob simple but i am yet to find a solution. any ideas ? Quote Link to comment Share on other sites More sharing options...
foxsoup Posted May 24, 2010 Share Posted May 24, 2010 Just echo the '...' after the cut-down text, e.g. <?php $data = 'Pulp Fiction'; echo substr($data, 0, 7) . '...'; ?> Quote Link to comment Share on other sites More sharing options...
jurass1c Posted May 24, 2010 Author Share Posted May 24, 2010 Thanks man, i am still having a little trouble. I did use this same method but what it does is echo all my results with an "..." after the substr even if the characters are under 7. so for example: Say i have a 3 names in my database (Orange, Apple, Strawberry) under the field "Fruit", say i want to limit the characters to "5" i use substr like above: ". substr($row['fruit'], 0, 5).'...' ." It will work perfect for both "Orange and Strawberry" but when it comes to "Apple" (which is 5 characters) it will echo the "..." after it when it does not need to. Any idea's ? Thanks. Quote Link to comment Share on other sites More sharing options...
ldb358 Posted May 25, 2010 Share Posted May 25, 2010 try: <?php $data = 'Pulp Fiction'; $out = substr($data, 0, 7); if(strlen($data > 7){ $out .= '...'; } echo $out; ?> Quote Link to comment Share on other sites More sharing options...
marcus Posted May 25, 2010 Share Posted May 25, 2010 <?php $r = array('Orange','Strawberry','Apple'); foreach($r AS $s){ echo substr(wordwrap($s,5,'...',true),0, . "<br>\n"; } ?> Results: Orang... Straw... Apple Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.