What are some best practices for handling multi-line text patterns in PHP using preg_match?
When dealing with multi-line text patterns in PHP using preg_match, it's important to use the "s" modifier to allow the dot (.) to match newline characters. This ensures that the pattern can correctly match across multiple lines in the input text.
$text = "This is a multi-line text pattern.
It spans across multiple lines.
Using preg_match with the 's' modifier allows matching across lines.";
$pattern = '/multi-line.*lines/s';
if (preg_match($pattern, $text, $matches)) {
echo "Match found: " . $matches[0];
} else {
echo "No match found.";
}