php-regexHow to use PHP regex to match a multiline?
Using PHP regex to match a multiline is possible with the /m modifier. This modifier allows the pattern to match across multiple lines.
Example code
$string = "This is a
multiline string";
$pattern = "/This.*string/m";
if (preg_match($pattern, $string)) {
    echo "Match found!";
}Output example
Match found!Code explanation
- $string: This is the string that will be searched for a match.
- $pattern: This is the regular expression pattern that will be used to search for a match.
- preg_match(): This is the PHP function used to search for a match. It takes two parameters, the regular expression pattern and the string to search.
- /m: This is the modifier used to allow the pattern to match across multiple lines.
Helpful links
More of Php Regex
- How to use PHP regex to match a zip code?
- How to use PHP regex to match an exact string?
- How to use PHP regex to match a nbsp HTML whitespace?
- How to use PHP regex to get a YouTube video ID?
- How to use PHP regex to match a year?
- How to use named capture groups in PHP regex?
- How to use PHP regex with the "x" modifier?
- How to use PHP regex to match an XML tag?
- How to use PHP regex to match UUID?
- How to use PHP regex with zero or more occurrences?
See more codes...