Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

First word of $content bold...


Go to End


9 Posts   5370 Views

Avatar
SpiritLevel

Community Member, 5 Posts

23 October 2015 at 1:23pm

Edited: 23/10/2015 1:24pm

For any string and any desired word, this is useful:

public function Word($string,$word_num) {
    if ( str_word_count($string) < $word_num ) {
        return null;
    } else {
        return str_word_count($string,1)[$word_num-1]; 
    }
}

Go to Top