如何在字符串的行末尾添加换行符; 使用preg_match_all到我的模式? PHP

I am trying to add line breaks using this pattern---- $pattern = "/^.$pattern.\$/m"; but I don't seem to get the results I want. Any help would be appreciated. Thanks.

Use s modifier.

$pattern = "/^.$pattern.\$/s";

http://php.net/manual/en/reference.pcre.pattern.modifiers.php