【发布时间】:2011-08-16 05:54:41
【问题描述】:
如果只是搜索一个词,那会很容易,但针可以是一个词,也可以不止一个词。
Example
$text = "Dude,I am going to watch a movie, maybe 2c Rio 3D or Water for Elephants, wanna come over";
$words_eg1 = array ('rio 3d', 'fast five', 'sould surfer');
$words_eg2 = array ('rio', 'fast five', 'sould surfer');
$words_eg3 = array ('Water for Elephants', 'fast five', 'sould surfer');
'
is_words_in_text ($words_eq1, $text) / true, 'Rio 3D' matches with 'rio 3d'
is_words_in_text ($words_eq2, $text) //true, 'Rio' matches with 'rio'
is_words_in_text ($words_eq3, $text) //true, 'Water for Elephants'
谢谢,
【问题讨论】:
-
你考虑过strpos:php.net/manual/en/function.strpos.php,看看下面的例子。
-
我投票结束,但这个问题有点不同,因为它处理不区分大小写的字符串和单词边界 - 你决定。