我想检查给定字符串是否是另一个字符串的子字符串。例如:
$a = 'Hello World!';
$b = 'ell';
$ b是$ a的子字符串。有什么功能可以检查吗?
答案 0 :(得分:1)
您可以使用strpos()
功能检查
<?php
if (strpos('Hello World!','ell') !== false) {
echo 'contains';
}
else echo 'not contains';
答案 1 :(得分:0)
试试这个
$a = 'Hello World!';
$b = 'ell';
if (strpos($a, $b) !== false) {
echo true; // In string
}
答案 2 :(得分:0)
$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";
}