// If not case sensitive
if (strpos($string,$lan) !== false) {
echo 'true';
}
// If case sensitive
if (stripos($string,$lan) !== false) {
echo 'true';
}
Check if variable value is same as string
-
18-07-2023 - |
题
I would like to have if condition which can validate PHP variable has value like string
$string = "language English"
$lan = "ENG"
//So $lan has value "ENG" which is in string
if($lan LIKE $string )
{
// DO some thing.
}
Is there way to check this? or any other ways, good examples, good practice.?
解决方案
其他提示
<?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";
}
?>
You can also use is_numeric function
if (!is_numeric("test"))
{
echo "Yes";
} else {
echo "No";
}
不隶属于 StackOverflow