What is the best way to check if a user input contains a specific string in PHP?

To check if a user input contains a specific string in PHP, you can use the strpos() function which returns the position of the first occurrence of a substring in a string. If the substring is not found, it returns false. You can use this function to check if the user input contains the specific string by comparing the result to false.

$userInput = $_POST['user_input']; // Assuming user input is received via POST method
$specificString = 'example'; // Specific string to check for

if (strpos($userInput, $specificString) !== false) {
    echo 'User input contains the specific string.';
} else {
    echo 'User input does not contain the specific string.';
}