How does the strpos() function work in PHP and how can it be used for filtering data?

The strpos() function in PHP is used to find the position of the first occurrence of a substring within a string. This function returns the position of the substring if found, or false if the substring is not found. It can be used for filtering data by checking if a certain substring exists within a string.

// Example of using strpos() for filtering data
$string = "Hello, world!";
$substring = "world";

if (strpos($string, $substring) !== false) {
    echo "Substring found in the string.";
} else {
    echo "Substring not found in the string.";
}