我想如果可以验证PHP变量的条件具有类似字符串
的值 $string = "language English"
$lan = "ENG"
//So $lan has value "ENG" which is in string
if($lan LIKE $string )
{
// DO some thing.
}
有没有办法检查这个?或任何其他方式,良好的例子,良好的做法。?
答案 0 :(得分:3)
// If not case sensitive
if (strpos($string,$lan) !== false) {
echo 'true';
}
// If case sensitive
if (stripos($string,$lan) !== false) {
echo 'true';
}
答案 1 :(得分:1)
<?php
$string = "language English";
$lan = "ENG";
$eng = '/'.$lan.'/i'; // 'i' indicates a case-insensitive search
$check=preg_match($eng, $string);
if($check)
{
echo "Match Found";
}
else
{
echo "Match not found";
}
?>
答案 2 :(得分:0)
You can also use is_numeric function
if (!is_numeric("test"))
{
echo "Yes";
} else {
echo "No";
}