To check if a string contains another string in PHP you can use the strpos function.

Sample PHP

if (strpos($variable,'checkstring') !== false) {
    echo 'string contains checkstring';
}

for more informations take a look at strpos — Find the position of the first occurrence of a substring in a string

One thought on “How to check if a string contains another string in PHP”

Leave a Reply