How to use strpos to determine if a string exists in input string?

后端 未结 7 1597
难免孤独
难免孤独 2020-12-03 17:17
$filename = \'my_upgrade(1).zip\';
$match = \'my_upgrade\';

if(!strpos($filename, $match))
    {
    die();
    }
else 
   {
   //proceed
   }

In

7条回答
  •  情书的邮戳
    2020-12-03 17:26

    The strpos() function is case-sensitive.

    if(strpos($filename, $match) !== false)
            {
            // $match is present in $filename
            }
        else 
           {
           // $match is not present in $filename 
           }
    

    For using case-insensitive. use stripos() that is it finds the position of the first occurrence of a string inside another string (case-insensitive)

提交回复
热议问题