I’m looking at a regular expression to match any characters. I know that the ‘.’ is a placeholder except for newline. Given this code below:
$fruits = "One\nTwo\nThree";
preg_match_all('/^(.*)$/', $str, $matches);
print_r($matches);
Why does it not match anything at all? I would think, $matches[0] would be One Two Three?
Add the modifier “s” to the regex:
Update:
If you enclose $fruits in single quotes, the newline isn’t treated as such and the replacement also works, event without the “s” modifier. But I don’t know if the output is what you expect it to be 😉