简体   繁体   English

php-搜索特定的子字符串

[英]php - search for specific substring

I am trying to figure out how to search in php for substring. 我试图弄清楚如何在php中搜索子字符串。 When I tried using this: 当我尝试使用此:

while ($row = db_fetch_array($results)) {
if(strpos($row['field_rep_contact_name_value'], $get)) {
  $names['suggestions'][] = $row['field_rep_contact_name_value'];
}
}

I found that when the $get value was 'arm', it returned true for strings which had 'ar', I only want it to return true if it contains 'arm', the full value of the $get variable. 我发现当$ get值为'arm'时,它对于具有'ar'的字符串返回true,我只希望它包含$ arm变量的完整值'arm'时返回true。 I think this can be done with regex but not exactly sure how. 我认为可以使用正则表达式完成此操作,但不能完全确定该怎么做。

Add a !== false to your statement 在语句中添加!== false

$stringone = 'lucas vieira';
$stringtwo = 'luca';

strpos($stringone, 'lucas') !== false // returns true

strpos($stringtwo, 'lucas') !== false // returns false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM