Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > PHP Q; cut text

PHP Q; cut text
Thread Tools
1c3
Forum Regular
Join Date: May 2003
Location: Jämtland - Sweden
Status: Offline
Reply With Quote
Jun 11, 2003, 06:07 PM
 
Anyone who knows how to cut a text?
Like if there is more than 15 characters, replace the rest with three dots or something.

I guess you know what I mean...
Mighty3k @ #MacNN
     
Dedicated MacNNer
Join Date: Aug 2002
Status: Offline
Reply With Quote
Jun 11, 2003, 08:20 PM
 
use the substr function

usage:

$cutstring = substr($string,int start,int length);

so in your case:
$cutstring = substr($string,0,15) . "...";

complete detail at
http://us2.php.net/manual/en/function.substr.php
     
Senior User
Join Date: Dec 2002
Status: Offline
Reply With Quote
Jun 12, 2003, 07:57 PM
 
Also, for your specific situation you'd want a conditional statement to check for a string > 15 characters. You don't want something 3 characters long to have (...).

To check string length, use strlen()
Travis Sanderson
     
1c3  (op)
Forum Regular
Join Date: May 2003
Location: Jämtland - Sweden
Status: Offline
Reply With Quote
Jun 17, 2003, 05:08 PM
 
thx
Mighty3k @ #MacNN
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:41 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2