找不到鬼回车/换行

时间:2017-10-13 01:28:40

标签: php html regex hexdump hex-editors

我有一个.php文件,其中包含openssl_pkcs7签名和正则表达式文件的file_get_contents,在回显它之前会进行修剪以供用户下载。

但是,下载的文件在文件的顶部/开头有一个换行符/换行符/回车符,这会破坏我后续的代码。当我在记事本++ / notepad中打开它时,签名和正则表达式的template.mobileconfig在文件的开头没有这个空行,但是当它通过浏览器下载时它就在那里。我对它的插入位置感到困惑,甚至在修剪它之后,它仍然存在。

代码:

header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=signed.mobileconfig");
$content = file_get_contents('./template.mobileconfig'); 
$trimmed = trim($content, " \t\n\r\0\x0B");
echo $trimmed;

下载的文件在notepad / notepad ++中显示如下:

enter image description here

第1行始终为空。我尝试过readfile()和trim()来尝试解决它但无济于事。

在线十六进制编辑器输出:

Output of a hex editor:

x0A显然是一个换行符,但它来自哪里?为什么没有修剪()摆脱它?

Line Feed x0A

2 个答案:

答案 0 :(得分:1)

您的include()之一可能有换行符\n

<?php
//code
?>     <======== \n right there (not visible)

查找所有包含的PHP文件,并在开始标记之前删除空格:

_
<?php 

摆脱结束标签(不需要):

?>

答案 1 :(得分:0)

我想到的是尝试将x0A添加到修剪中。

$trimmed = trim($content, " \t\n\r\0\x0B\x0A");
相关问题