jesushax Posted March 20, 2008 Share Posted March 20, 2008 hi i was wonderin ghow to do the above i want to only disaply acertain number of characters of a record then when it reaches a certain point put "..." anyoe know? cheers Quote Link to comment Share on other sites More sharing options...
Perad Posted March 20, 2008 Share Posted March 20, 2008 Use substr(). Then add ... on the end http://uk.php.net/manual/en/function.substr.php Quote Link to comment Share on other sites More sharing options...
jesushax Posted March 20, 2008 Author Share Posted March 20, 2008 tanks Quote Link to comment Share on other sites More sharing options...
Aureole Posted March 20, 2008 Share Posted March 20, 2008 The only problem with using substr() is words may get cut off half way through, if you don't want that to happen you could do something like this: <?php $puzzle; $counter = 1; $words = 15; $full_article = 'I am an article, blah blah blah. You find the topic that I am based on extremely interesting and you want to read more of me.'; $pieces = explode( ' ', $full_article ); foreach( $pieces as $piece ) { $counter++; $puzzle .= $piece . ' '; if( $counter > $words ) break; } $puzzle = rtrim( $puzzle ) . '...'; echo( $puzzle ); ?> There are probably better ways of doing it, but it works... 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.