在 PHP 中删除新行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6766551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Strip new lines in PHP
提问by pt2ph8
I've been working with phrases the past couple of days and the only problem I seem to be facing is stripping new lines in the html before printing it.
过去几天我一直在处理短语,我似乎面临的唯一问题是在打印 html 之前去除 html 中的新行。
Anybody have any idea how to remove everynew lines from HTML using PHP?
任何人都知道如何使用 PHP 从 HTML 中删除每个新行?
回答by pt2ph8
str_replace(array("\r", "\n"), '', $string)
回答by user319730
the pt2ph8answer didn't work for me until I have changed it a little bit as follows:
在pt2ph8答案为我所做的,直到我已经改变了它一点点如下不起作用:
str_replace(array("\r", "\n"), '', $string);
You can see the different results in this demo:
您可以在此演示中看到不同的结果: