什么会导致 html 代码格式在 php 页面中消失?

发布于 2024-12-17 15:43:02 字数 579 浏览 2 评论 0原文

我有一个用 php 编写的页面,由于某种原因,文件 index.php 的所有纯 html 内容都在一行上(查看源代码)空白被保留,但所有换行符都消失了。

除了语法错误之外,我无法想出为什么会发生这种情况,但我仔细梳理了一下,没有发现任何不合适的地方。这只发生在index.php 页面上。

有人对我应该寻找什么有任何想法吗?如果需要的话我可以发布更多代码。

<?php
//...
include('ssi/header.php');
?>

<div>
  <section id="charters">
    <h2><a href="charters.php">Tanker Chartering</a></h2>
     <!-- ... -->

上面的代码的计算结果如下:

<div>      <section id="charters">        <h2><a href="charters.php">Tanker ...

I have a page written with php where, for some reason, all of the plain html content of the file index.php goes on one line (look at the source) The white space is preserved, but all the new-lines disappear.

I cannot come up with any reason why this would happen, short of a syntax error, but I went through with a fine toothed comb, and found nothing out of place. This only happens on the index.php page.

Anyone have any Ideas what I should be looking for? I can post more code if necessary.

<?php
//...
include('ssi/header.php');
?>

<div>
  <section id="charters">
    <h2><a href="charters.php">Tanker Chartering</a></h2>
     <!-- ... -->

The above code evaluates to something like this:

<div>      <section id="charters">        <h2><a href="charters.php">Tanker ...

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

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

发布评论

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

评论(3

不必在意 2024-12-24 15:43:03

也许你有linux服务器并且使用的是windows系统。不同的操作系统使用不同的换行符。另外,对于一台服务器,我的 FTP 客户端上传的格式错误,并且错过了每个换行符。

还有像这样的应用程序
Notepad++ 使您能够更改格式和换行符。

Maybe you have linux server and you're using windows system. Different operating systems use different new line characters. Also, for one server my FTP client uploaded it with wrong formatting, and missed every line break.

Also applications like
Notepad++ gives you the ability to change formatting and linebreaks.

转角预定愛 2024-12-24 15:43:03

这可能是文件的编码与您下载/上传文件的 ftp 上的传输模式相结合。尝试使用 notepad2 之类的工具,并将文件保存为 UTF-8 而不是 ANSI。还可以使用 FTP 程序以二进制而非 ASCII 格式上传/下载。这解决了我所有的 PHP 换行问题。

It's probably the encoding of the file combined with the transfer mode on the ftp from which you downloaded/uploaded the file. Try using something like notepad2, and saving the file in UTF-8 rather than ANSI. Also upload/download with your FTP program in binary not ASCII. That stopped all of my newline issues with PHP.

人疚 2024-12-24 15:43:03

是否您的托管提供商正在为您进行某种最小化?没有换行符意味着更少的字符被推入线中​​。

could it be that your hosting provider is doing some kind of minimization for you? no newlines means less characters pused down the wire.

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