/ Published in: PHP
Public domain.
Expand |
Embed | Plain Text
Comments
Subscribe to comments
You need to login to post a comment.
jatkins on 08/10/10
2 people have marked this snippet as a favorite
Public domain.
Subscribe to comments
You need to login to post a comment.
It seems to me that using preg_split or even explode with a limit of 3 would be the ideal solution.
Then return "$array[0] $array[1]";
Perhaps:
function firsttwowords($string) { $array = explode(' ', $string, 3); return "$array[0] $array[1]"; }
Yeah, that's a shorter way of doing it. The only reason for me using the string functions was to find a way to do it without having to store it in an array first, but it doesn't really matter which method you use.