![](/img/trans.png)
[英]Php in_array / strpos does not work - How to find an 'exact' match?
[英]How to find exact match using strpos?
如果我寻找war
,如果我查看Award
也可以找到:
$title = "Music award";
if (strpos($title, 'war') !== false) {
echo "found";
}
如果我寻求war
我不想获得award
使用正则表达式匹配
$title = "Music award";
if (preg_match('/\bwar\b/', $title) !== false) {
echo "found";
}
<?php
$string = "We are the music makers and we are the dreamers of dreams.";
$words = str_word_count($string, 1);
var_dump(in_array('music', $words));
var_dump(in_array('dream', $words));
输出:
bool(true)
bool(false)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.