How can the strpos function be effectively used in conjunction with date functions in PHP to search for specific patterns in text strings?

When using the strpos function in conjunction with date functions in PHP to search for specific patterns in text strings, you can search for date patterns within the text and extract relevant information. For example, you can search for dates in the format "YYYY-MM-DD" within a text string using strpos and then extract the date using substr. This can be useful when parsing text data that contains date information.

$text = "The event will take place on 2022-12-31 at 8:00 PM";
$datePattern = "YYYY-MM-DD";

$pos = strpos($text, $datePattern);

if ($pos !== false) {
    $date = substr($text, $pos, strlen($datePattern));
    echo "Date found: " . $date;
} else {
    echo "Date pattern not found in text.";
}