Does String Contain String
str_contains
if (str_contains($MyString, 'hello')) //Returns true or false
{
echo 'true';
}
strpos()
strpos ($haystack , $needle , $offset = 0 )
Returns False on no match or first occurrence index (from 0) on match
if (strpos($MyString, 'hello') !== False)
{
echo 'true';
}
$char_index = strpos( strtolower($StringToCheck), strtolower($LookingForString)); //Using strtolower() removes case sensitivity
if($char_index === false)
{
//Not found
}
else
{
//Found
}
Does string start with
if (str_starts_with($StringToCheck, $LookingForString)) //True if it starts with, false otherwise
Does string end with
if (str_ends_with($StringToCheck, $LookingForString)) //True if it ends with, false otherwise
