What function can be used in PHP to search for a specific substring within a variable?
To search for a specific substring within a variable in PHP, you can use the strpos() function. This function returns the position of the first occurrence of a substring within a string, or false if the substring is not found. You can use this function to check if a specific substring exists within a variable and then take appropriate actions based on the result.
$variable = "This is a sample string";
$substring = "sample";
if(strpos($variable, $substring) !== false) {
echo "Substring found in the variable.";
} else {
echo "Substring not found in the variable.";
}