检查word是否为子字符串-php
我想检查一个给定的字符串是否是另一个字符串的子字符串。例如:检查word是否为子字符串-php,php,Php,我想检查一个给定的字符串是否是另一个字符串的子字符串。例如: $a = 'Hello World!'; $b = 'ell'; $b是$a的子字符串。有什么函数可以检查这个吗?试试这个 $a = 'Hello World!'; $b = 'ell'; if (strpos($a, $b) !== false) { echo true; // In string } 您可以使用strpos()函数来检查 <?php if (strpos('Hello Wo
$a = 'Hello World!';
$b = 'ell';
$b是$a的子字符串。有什么函数可以检查这个吗?试试这个
$a = 'Hello World!';
$b = 'ell';
if (strpos($a, $b) !== false) {
echo true; // In string
}
您可以使用strpos()
函数来检查
<?php
if (strpos('Hello World!','ell') !== false) {
echo 'contains';
}
else echo 'not contains';
你试过用谷歌搜索吗?你考虑过用谷歌搜索你的问题吗?我唯一找到的是substr,但它的工作原理类似(“abcdef”,-1);正当它不比较两个字符串?请尝试可能重复的
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}