奇怪的 PHP 输出损坏

发布于 2024-08-20 06:14:02 字数 999 浏览 3 评论 0 原文

我的一个 PHP 站点上出现了非常奇怪的输出损坏。有时,会显示一段 HTML 代码,而不是解释标签。看起来有些字符丢失了,弄乱了标签。请参见下面的示例:第二行应该只是指向 c1 的链接,但由于某种原因显示了部分目标 URL。

替代文本 http://trappist.elis.ugent.be/~ wheirman/atuin/tmp/phpstrangeness.png

问题是暂时的,刷新通常可以解决它。这可能发生在页面的不同部分(尽管通常发生在同一位置)。只有 Safari 似乎受到影响(但我怀疑 Firefox 只是由于更宽容的解析而掩盖了问题)。它发生在我的开发服务器和实时服务器上,它们的设置都略有不同(输出缓冲、分块传输),尽管发生的概率似乎有所不同。

有人见过这样的事情吗??

编辑

当我在此页面上的 Safari 中“查看源代码”时,我得到以下 HTML:

<tr class="odd">
  <td>73</td>
  <td><a href="companies.php?view=1&amp;companyid=73&amp;return=%2Foffice%2Fcompanies.php">c1</a></td>
  <td></td>
  <td><img src='/images/dot_blue.png'  class="altTooltip" alt="inactive: no account"  /> </td>

我看不出这有什么问题,所以当我要求 Safari 提供源代码时,Safari 已重新加载该页面,或者我还不够努力......

I'm having a very strange output corruption on one of my PHP sites. Sometimes, a piece of HTML code is displayed, rather than the tags being interpreted. It looks like some characters are missing, messing up the tags. See the example below: the second line should just be a link to c1, but due to some reason part of the target URL is shown.

alt text http://trappist.elis.ugent.be/~wheirman/atuin/tmp/phpstrangeness.png

The problem is temporary, a refresh usually solves it. This can happen on different parts of the page (although often in the same location). Only Safari seems affected (but I'm suspecting Firefox just masks the problem due to more tolerant parsing). It happens on both my development server as the live one, they both have slightly different settings (output buffering, chunked transfer), although the probability of it happening seems to vary.

Anyone ever seen something like this??

EDIT

When I "View Source" in Safari on this page, I get the following HTML:

<tr class="odd">
  <td>73</td>
  <td><a href="companies.php?view=1&companyid=73&return=%2Foffice%2Fcompanies.php">c1</a></td>
  <td></td>
  <td><img src='/images/dot_blue.png'  class="altTooltip" alt="inactive: no account"  /> </td>

I can't see anything wrong with this, so either Safari has reloaded the page when I asked it for the source, or I'm not looking hard enough...

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

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

发布评论

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

评论(3

涙—继续流 2024-08-27 06:14:02

好吧,这是我在黑暗中拍摄的。

中断发生在单词“office”中,位于 fi 字符组合之后。我敢打赌 fi 连字 不知何故会造成麻烦。

具体如何?由于该 HTML 代码不包含连字字符,因此这可能是 Safari 中的错误。特别是因为它是随机发生的。您可以尝试重命名该文件,看看问题是否消失吗?

拥有有效的 HTML 也可能有助于避免此问题,因为它使解析更容易。

Well, here's my shot in the dark.

The break occurs in the word "office", after the fi character combination. I would bet that the fi ligature is -- somehow -- causing trouble.

How exactly? Since that HTML code doesn't contain the ligature character, this might be a bug in Safari. Especially since it occurs randomly. Could you try to rename that file, and see if the problem goes away?

Having valid HTML might also help in avoiding this problem, because it makes parsing easier.

内心荒芜 2024-08-27 06:14:02

当您选择一段 HTML 并查看源代码时,您得到的并不是 100% 的内容。例如,你们所有人都是 &,这可能意味着您选择了有问题的文本并查看了所选内容的源代码。

如果您仍然遇到问题,请尝试查看整个源代码而不选择任何内容,然后使用 ctrl + f 查找代码中的位置,并尝试为我们提供更大的样本,不仅仅是有问题的行,而是正确的行行,并在更大的背景下。

例如,在使用表格时,错误放置的 可能会产生非常奇怪的后果,这看起来不像那种类型的问题,我只是说我们需要上下文才能提供帮助。

还有一个问题是,某些浏览器为了查看源代码,实际上会重新提交页面并获取它的第二个副本。我有一种感觉,它是输出文本的代码,所以看看你是否使用类似的东西

<?= $someVar ?>

,并确保它不是这样的:

<a href=<?= isset($x) ?'"'. $someVar.'"': '"'.$someOlderVar.'">'?>> xxx </a>

所以,没有选择性,请提供更大的样本。我们可能需要从输出错误 HTML 的代码中获取一些内容......

When you select a piece of HTML and view source, what you get is not 100% what is there. For instance, all of you &'s are &, which probably means you selected the offending text and viewed the selection's source.

If you are still having the issue, trying viewing the whole source code without selecting anything, and then using ctrl + f to find the spot in the code, and try and give us a larger sample, not just the offending row, but a correct row, and in a larger context.

For instance, when using tables, a mislaid <td> can have very weird consequences, this doesn't look like that type of issue, I am just saying that we need context to be able to help.

There's also the issue that some browsers, in order to view source, actually resubmit the page and get a second copy of it. I have a feeling that it is the code that's outputting the text, so look and see if you are using something like

<?= $someVar ?>

and make sure it's not like this:

<a href=<?= isset($x) ?'"'. $someVar.'"': '"'.$someOlderVar.'">'?>> xxx </a>

So, no selecty, and bigger sample please. And we'd prolly need something from the code that outputs the errored HTML...

北城孤痞 2024-08-27 06:14:02

我终于发现了问题(使用 Web Inspector):TinyMCE 一直在我自己的 HTML 中看似随机的位置插入标签(它用来加载语言文件和扩展模块)。结果是,在我的屏幕截图中可见的情况下,类似于 bar.php">foobar。

由于我也在同一页面上使用 jQuery,我猜测这最终是由于 jQuery 对 DOM 的修改和 TinyMCE 的添加同时发生而导致的,这导致了某种竞争条件(由一个似乎只出现的错误引起)在 Safari 中展示自己)。

我现在正在使用 TinyMCE 的 jQuery 版本,自那以后一切都很好......

感谢大家的帮助!

I finally found the problem (using Web Inspector): TinyMCE has been inserting tags (which it uses to load language files and extension modules), at seemingly random places inside my own HTML. The result was that, in the case visible from my screenshot, something like <a href="foo<script src="tinymce/lang/en.js">bar.php">foobar</a>.

Since I'm also using jQuery on the same page, my guess is it was ultimately cause by jQuery's modifications to the DOM and TinyMCE's additions happening at the same time which resulted in some sort of race condition (caused by a bug that only appears to exhibit itself in Safari).

I am now using the jQuery build of TinyMCE, and all has been well since...

Thanks to everyone for the help!

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