Does Yii have methods to do this?

I have a description field that is 500 characters long, on a certain screen in my application I only want it to display the first 10 words of the 500 character description?

Does Yii have methods to do this?

You can use PHP for this…

If you have a string than you can do something like




   preg_match("/^(\S+\s+){0,10}/", $string, $matches);

   echo trim($matches[0]) . '...';



On the other side MySQL does have a handy function for this, so you get just the first 10 words…


SELECT SUBSTRING_INDEX(text_field, ' ', 10) FROM ...