limiting a strings word count
Posted: Tue Mar 29, 2011 8:14 am
hello there. I'm currently trying to edit a wordpress theme's php function which is a bit tricky for me as I don't know php.
was wondering if some nice fellow/fellowess could help?
The function at the moment counts the string's character length. If it's over a certain number- it displays a certain number of characters from the string and adds "..." to it.
here's what I have so far:
function bm_better_excerpt($length, $ellipsis) {
$text = get_the_content();
$text = strip_tags($text);
if($length > 20){
$text = substr($text, 0, 20);
$text = $text.$ellipsis;
return $text;
}
return $text;
}
apologies if I'm missing any needed info. I'm not really writing php code. I'm more... editing(messing up) what's already there
But, to the point- what I'd really like to do is have it count the number of words in the string and then if it's too high- output a certain amount of words + the ellipsis.
Could someone assist me?
Thanks,
-Will
was wondering if some nice fellow/fellowess could help?
The function at the moment counts the string's character length. If it's over a certain number- it displays a certain number of characters from the string and adds "..." to it.
here's what I have so far:
function bm_better_excerpt($length, $ellipsis) {
$text = get_the_content();
$text = strip_tags($text);
if($length > 20){
$text = substr($text, 0, 20);
$text = $text.$ellipsis;
return $text;
}
return $text;
}
apologies if I'm missing any needed info. I'm not really writing php code. I'm more... editing(messing up) what's already there
But, to the point- what I'd really like to do is have it count the number of words in the string and then if it's too high- output a certain amount of words + the ellipsis.
Could someone assist me?
Thanks,
-Will