Reeeece Posted January 24, 2012 Share Posted January 24, 2012 Sorry if this is too obvious or hard to understand. I'm echoing a database value onto a webpage, the value in question is a large paragraph of text. I need it to only display the first 40 characters or so of that text, then trail off with a "..." So the users will be able to click a 'More Info' button which will take them to a page containing the full paragraph of text. I'm just not sure how to cut off the text after 40 characters. Any help HUGELY appreciated Quote Link to comment https://forums.phpfreaks.com/topic/255642-display-snippet-of-text-but-not-all/ Share on other sites More sharing options...
Pikachu2000 Posted January 24, 2012 Share Posted January 24, 2012 If it were me, I'd use MySQL's SUBSTRING() and CONCAT() functions. You could also use PHP's substr. Quote Link to comment https://forums.phpfreaks.com/topic/255642-display-snippet-of-text-but-not-all/#findComment-1310503 Share on other sites More sharing options...
litebearer Posted January 24, 2012 Share Posted January 24, 2012 A small teaser for you ... // remove double spaces from the contents $doubles = " "; $contents = str_replace($doubles," ",$contents); // get the first xx words for the teaser if (count(explode(" ", $contents))> $max_words) { $contents = substr($contents, 0, strnpos($contents, " ", $max_words)); } $contents = $contents . "..."; Quote Link to comment https://forums.phpfreaks.com/topic/255642-display-snippet-of-text-but-not-all/#findComment-1310516 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.