好的,这就是我需要的...
示例输入:
$str = "Well, I guess I know what this # is : it is a & ball";
示例输出:
firstWords($str,5)
应该返回Array("Well","I","guess","I","know")
lastWords($str,5)
应该返回Array("is","it","is","a","ball")
我已经尝试过自定义正则表达式和str_word_count
,但我仍然觉得好像我错过了一些东西。
有任何想法吗?