从html源代码中删除所有换行符 [英] Remove all the line breaks from the html source
本文介绍了从html源代码中删除所有换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
\\\
\r
,但不知道如何做到这一点。如果我不清楚这里是一个例子 $ output ='< p>
< div class =title>你好< / div>
< / p>';
echo $ output;
要在源代码查看器中查看为< p>< div class =title> Hello< / div>< / p>
解决方案
这个?
$ output = str_replace(array(\r\,\r), \\\
,$ output);
$ lines = explode(\\\
,$ output);
$ new_lines = array();
$ b $ foreach($ lines as $ i => $ line){
if(!empty($ line))
$ new_lines [] = trim($ line);
}
echo implode($ new_lines);
Well I know obfuscation is a bad idea. But I want all of my html code to come in one long single line. All the html tags are generated through PHP, so I think its possible. I knew replacing \n\r
from regular expression, but have no idea how to do this one. In case I am unclear here is an example
$output = '<p>
<div class="title">Hello</div>
</p>';
echo $output;
To be view in the source viewer as <p><div class="title">Hello</div></p>
解决方案
Maybe this?
$output = str_replace(array("\r\n", "\r"), "\n", $output);
$lines = explode("\n", $output);
$new_lines = array();
foreach ($lines as $i => $line) {
if(!empty($line))
$new_lines[] = trim($line);
}
echo implode($new_lines);
这篇关于从html源代码中删除所有换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文