检查变量值是否与字符串相同

时间:2014-05-08 13:19:49

标签: php if-statement

我想如果可以验证PHP变量的条件具有类似字符串

的值
 $string = "language English"
 $lan = "ENG"
 //So $lan has value "ENG" which is in string 
 if($lan LIKE $string )
 {
         // DO some thing.
 }

有没有办法检查这个?或任何其他方式,良好的例子,良好的做法。?

3 个答案:

答案 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";
 }