2014-09-11 60 views
-3

我想检查给定的字符串是否是另一个字符串的子字符串。例如:检查单词是否是子字符串 - php

$a = 'Hello World!'; 
$b = 'ell'; 

$ b是$ a的子字符串。任何可以检查这个功能的功能?

+0

你有没有尝试谷歌吗? – Vucko 2014-09-11 11:07:43

+0

您是否考虑过使用Google搜索您的问题? – 2014-09-11 11:07:48

+0

我发现的唯一的东西是substr,但它的工作原理就像(“abcdef”,-1);对?它不比较2个字符串? – Chris 2014-09-11 11:09:21

回答

0

试试这个

$a = 'Hello World!'; 
$b = 'ell'; 
if (strpos($a, $b) !== false) { 
    echo true; // In string 
} 
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"; 
}