Page 1 of 1
Can you restrict number of words show?
Posted: Mon Jan 20, 2014 6:18 am
by simonmlewis
Code: Select all
$boneyard=100; //Defines how many characters will be displayed from content field.
$postyard = substr($row->description,0,$boneyard);
echo "$postyard <font color='#cccccc'>...</font>";
We are trying to show a set number of words from the description to show on the category page, but doing it as Characters isn't working as you get half the word.
So, is there a way to do this, but for WORDS not characters?
Re: Can you restrict number of words show?
Posted: Mon Jan 20, 2014 6:24 am
by Celauran
substr down to 100 chars, then print up to strrpos of space character? Maybe throw a trim on the end to remove punctuation as needed?
Re: Can you restrict number of words show?
Posted: Mon Jan 20, 2014 12:50 pm
by requinix
str_word_count can return an array of the words in a string and
array_slice can get you a portion of an array...