How can the preg_match function be used to search for patterns in text, especially when dealing with line breaks?

When using the preg_match function to search for patterns in text that include line breaks, it's important to use the "s" modifier in the regular expression pattern. This modifier allows the dot (.) metacharacter to match all characters, including line breaks. By including the "s" modifier, the preg_match function will be able to correctly search for patterns across multiple lines in the text.

$text = "This is a sample text
with line breaks
that we want to search for patterns in.";

$pattern = '/sample text.*line breaks/s';

if (preg_match($pattern, $text, $matches)) {
    echo "Pattern found: " . $matches[0];
} else {
    echo "Pattern not found";
}