读取 HTML 内容并回显后的空格

发布于 2024-12-07 15:28:33 字数 510 浏览 1 评论 0原文

我有一个index.php文件,它将用在index.php文件中调用的函数准备的返回的.html文件来回显字符串

index.php:

require_once('functions.php'); 
echo create_page();

functions.php:

function create_page() {
    $result = file_get_contents('index.html');
    return $result;
}

问题是每次, html 是用这个函数生成的,我在页面底部有一个间隙。

如果我使用 str_replace 将多个 .html 页面包含到一个 .html 页面中,则每个替换的顶部都会有一个间隙。

如果我通过双击显示 .html 文件,它将显示在底部没有间隙。

我在这里做错了什么?

脚本中没有额外的回声。

I have an index.php-file, which will echo the string with the returned .html-file prepared by the function which is called in the index.php-file

index.php:

require_once('functions.php'); 
echo create_page();

functions.php:

function create_page() {
    $result = file_get_contents('index.html');
    return $result;
}

The problem is that everytime, the html is generated with this functions, I have a gap at the bottom of the page.

If I include several .html-pages into a .html-page with str_replace, a gap is at the top of every replacement.

If I display the .html-file by double-clicking it, it will be displayed without a gap at the bottom.

What am I doing wrong here?

There are no additional echos in the script.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海夜未眠 2024-12-14 15:28:33

检查你的 php 文件,我敢打赌它们在 php 结束标记 (?>) 之后包含一些新行/空格/制表符/其他白色 psace 字符。最好是省略这个结束标记,然后文件末尾的每个空格都将被视为 php 源(无害)并且不会产生任何输出。

Check your php files, I bet they contain some new lines / spaces / tabs / other-white psace characters after php closing tag (?>). The best is to omit this closing tag, then every whitespace from the end of file will be treated as php source (harmless) and will not produce any output.

北恋 2024-12-14 15:28:33

好的,解决方案如下:

在文本编辑器设置中不允许使用 BOM!

BOM 无法从浏览器中进行解释,因此他在每个启用了 BOM 的文件的底部添加了间隙。 ..

希望它对其他人有帮助!

谢谢大家!

Ok Here ist the soluton:

Don't allow BOM in your texteditor-settings!

The BOM could not be interpreted from the browser, so he added the gap at the bottom of every file which has BOM enabled...

Hope it helps someone else!

Thank you everyone!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文