substr like function to work on complete words
i am using substr to trim the first 100 characters from 开发者_JAVA百科the string. however i need a function that can trim a particular number of words, instead of characters from a string?
$trimmed_details = substr($row->details, 0, 200).'...';
is there a built in function to do that?
Try this:
join(" ", explode(" ", $yourStr, 100));
No, there is no builtin function in both PHP and mysql. Because there is no data type "word (of language)" in the either system. You can invent some regexp to do this, but I'd avise to just give up and use old char-based trimming.
精彩评论