What are the potential pitfalls of using strstr() to search for numbers in a string?
Using strstr() to search for numbers in a string can be problematic because it only searches for substrings, not specific patterns like numbers. This means it may return false positives or miss numbers that are not in the expected format. To accurately search for numbers in a string, it is better to use regular expressions with functions like preg_match().
$string = "There are 123 apples and 456 oranges.";
$pattern = '/\d+/';
if (preg_match($pattern, $string, $matches)) {
echo "Number found: " . $matches[0];
} else {
echo "No numbers found in the string.";
}