我怎样才能在PHP中获取字符串中给定关键字前后的[x]个单词?我正在尝试将针对关键字定制的mysql查询的结果标记为片段。 最佳答案 $string='Thisisateststringtoseehowtograbwordsfromanarbitrarysentence.It\'salittlehacky(asyoucanseefromtheresults)-butgenerallyspeaking,itworks.';echo$string,'';functiongetWords($string,$word,$before=0,$