Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从html(php)文件中删除换行符_Php_Html_Split_Line_Break - Fatal编程技术网

从html(php)文件中删除换行符

从html(php)文件中删除换行符,php,html,split,line,break,Php,Html,Split,Line,Break,我已经搜索过这个问题,我想从html中删除换行符,但是html文件中有一些分割的php行,例如: <html> <head> <title><?='abc'?></title> </head> <?php if($_SESSION['test'] == 'yes'){ echo 'hello'; } ?> 123456 43567 <?='13245tryt57u68'?> </body>

我已经搜索过这个问题,我想从html中删除换行符,但是html文件中有一些分割的php行,例如:

<html>
<head>
<title><?='abc'?></title>
</head>
<?php
if($_SESSION['test'] == 'yes'){
echo 'hello';
}
?>
123456
43567
<?='13245tryt57u68'?>
</body>
</html>

123456
43567

如何从这个php文件中删除换行符?

如果您想在IDE中使用它: 使用replace函数,并且不使用字符替换\n

如果您想为客户机使用它: 您必须配置htaccess,以便在将文件发送到客户端时删除换行符/缩进,即使用mod_pagespeed扩展名:
和collapse_whitespace选项

您可以使用
ob_start()


123456
43567
结果:

<html><head><title>abc</title></head><body>1234564356713245tryt57u68</body></html>
ABC12345643566713245TRYT57U68

可能需要解释为什么要删除换行符。它们造成了什么问题?Php代码不会呈现到浏览器中,因此尽管您有一个换行符来使文件看起来整洁,但它不会显示在页面上。请使用更好的源代码编辑器…这里的“换行符”是什么意思?您是指“GZIP”,开头的标签是什么,如果您有任何内联javascript,请记住关闭每一行,否则您可能会发现您的js无法工作:)
<html><head><title>abc</title></head><body>1234564356713245tryt57u68</body></html>