Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am very confused about the m modifier and to make it more confusing i'm confused by the key word multi line. That word is used to describe the m modifier at most sources

online. So what does multi line mean in the use of a m modifier? Is a multi line multiple variables that contains strings or by the word multi line is it referring to

multiple new lines with the \n command in one variable string? And is multi line based on one string? If any one can adjust this code example below to give me the correct code structure for the m

modifier and a better understanding by the word multi line is referring to, I will really appreciate that. So I can understand the m modifier and the word multi line use in PHP regular expressions.

PHP
<?php
$string = 'JavaScript is cool and I love JavaScript.';
if(preg_match_all('/JavaScript/m',$string))
{
echo 'bla bla 1.';
}
else
{
echo 'bla bla 2';
}
?>


What I have tried:

Explained online but rare code examples of this is provider online.
Posted
Updated 19-Jan-18 5:26am

 
Share this answer
 
Comments
[no name] 18-Jan-18 19:44pm    
What does multi line mean in PHP is it referring to multiple of these \n as a multi line? Can you provide a PHP example based on my example or do you even know how?
By default, PCRE treats the subject string as consisting of a single "line" of characters (even if it actually contains several newlines). The "start of line" metacharacter (^) matches only at the start of the string, while the "end of line" metacharacter ($) matches only at the end of the string, or before a terminating newline (unless D modifier is set). This is the same as Perl. When this modifier is set, the "start of line" and "end of line" constructs match immediately following or immediately before any newline in the subject string, respectively, as well as at the very start and end. This is equivalent to Perl's /m modifier. If there are no "\n" characters in a subject string, or no occurrences of ^ or $ in a pattern, setting this modifier has no effect.

So in your example, since the pattern doesn't contain either ^ or $, the modifier has no effect.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900