保留换行符 - PHP变量

时间:2015-02-17 14:04:39

标签: php

最简单的解释方法就是这样。

$find = "Hello
this is a new line";

$replace = "More content
Hello
this is a new line
this is an even newer line";

if(strpos($replace, $find) !== false) {
   //We have a match
}

如果我使用strpos,它会忽略换行符,这意味着当事实上第2行和第3行与$find匹配时,它在替换中找不到匹配项。有没有办法解决这个问题?

$find$replace需要使用函数动态化。我尝试了str_replace,但也找不到匹配项。它实际上将$find输出为Hello this is a new line。它删除了换行符并将其替换为空格。

0 个答案:

没有答案