简体   繁体   English

如何确定$ match是否在$ string中?

[英]How to determine if $match is in $string?

$string = "Test String for the test";
$match = "test string";

How to determine if $match is in $string? 如何确定$ match是否在$ string中?

You can use stripos to find the position of $match in $string with a case-insensitive search: 您可以使用stripos通过不区分大小写的搜索在$string找到$match的位置:

$pos = stripos($string, $match);

Note to compare this with a type-safe comparison operator like === or !== . 请注意将其与类型安全的比较运算符(例如===!== 进行比较 Because if $match is at the begin of $string like in this case, stripos returns 0 and (boolean) 0 === false . 因为在这种情况下,如果$match$string的开头,则stripos返回0并且(boolean) 0 === false

use strpos to check if it is in the string. 使用strpos检查它是否在字符串中。 API Link API链接

For case insensitive, use stripos . 如果不区分大小写,请使用stripos API Link API链接

使用stristr($haystack, $needle)http : stristr($haystack, $needle)

$boolean = stristr($string, $match);

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

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