PHP Print 在打印开始时在网页中放入虚假字符 ()

发布于 2024-09-14 06:26:19 字数 793 浏览 2 评论 0原文

当我在页面中包含一些 PHP 来填充 HTML 负载时,所有内容都以字符“”开头。这可能很愚蠢,但它让我发疯。我是 PHP 的新手,所以请小心。

这是我的包含语句

这是造成损害的代码,

   print <<<END
<a href="$pgurl">
<div id="layer1" style="background: url('$picurl'); 
position: absolute; width: 150px; height: 41px; z-index: 1; color: #FFFFFF; font: caption;
left: 14px; top: $topstr;
font-family: Arial, Helvetica, sans-serif; font-weight: bolder; text-decoration: none;
text-transform: capitalize; text-align: center; vertical-align: middle; font-size: xx-small;">
<br>
<font size="+0">$pgnm</font>
</div>
</a>
END;

它在程序的循环中多次输出,这只是我的第一次获取虚假字符。

请帮助

史蒂夫K

When I include some PHP in my page to populate a load of HTML everything is preceeded with the characters . It's probably something daft but it's driving me nuts. I'm a newcomer to PHP so kid gloves please.

This is my include statement <?php $PSName="Solar Numbers"; $whereto="bot"; include("../php/menu.inc.php");?>

and this is the code that's doing the damage

   print <<<END
<a href="$pgurl">
<div id="layer1" style="background: url('$picurl'); 
position: absolute; width: 150px; height: 41px; z-index: 1; color: #FFFFFF; font: caption;
left: 14px; top: $topstr;
font-family: Arial, Helvetica, sans-serif; font-weight: bolder; text-decoration: none;
text-transform: capitalize; text-align: center; vertical-align: middle; font-size: xx-small;">
<br>
<font size="+0">$pgnm</font>
</div>
</a>
END;

it's output several times in a loop in the program and it's only the first time round I get the spurious characters.

Help please

SteveK

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

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

发布评论

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

评论(4

与之呼应 2024-09-21 06:26:19

将文件另存为 UTF-8,不带签名 (BOM)。

这些字符是 Unicode 代码点 U+FEFF,UCS-2、UCS-4、UTF-16 和 UTF-32 需要它来指示字节顺序(小端或大端)——代码点本身为零-width不间断空间。这意味着任何不剥离它的应用程序只要支持 Unicode 输出就不会遇到问题。但是,如果您的 PHP 文件以其开头(UTF-8),则 PHP 不够智能,无法对其执行任何操作,并且由于 PHP 认为它是页面内容,因此它将被打印。这也意味着如果发生这种情况,您将无法执行重定向或设置 cookie 或启动会话,因为 PHP 已经发送了部分页面输出。

Save the file as UTF-8 without the signature (BOM).

Those characters are the Unicode code point U+FEFF which is needed for UCS-2, UCS-4, UTF-16 and UTF-32 to indicate the byte order (little- or big-endian) – the code point itself is a zero-width no-break space. That means any application not stripping it won't run into problems as long as it supports Unicode output. However, if your PHP file begins with it (in UTF-8), PHP is not smart enough to do anything with it and since it's page content as far as PHP is concerned, it will get printed. This also means that you can't do a redirect or set cookies or start a session if this happens as PHP already sent part of the page output.

︶ ̄淡然 2024-09-21 06:26:19

这些字符看起来像 UTF-8 BOM 字符。

The characters look like UTF-8 BOM characters.

泼猴你往哪里跑 2024-09-21 06:26:19

如果您使用Dreamweaver,“源文件创建”的预选选项是:

use utf8 BOM [x]

取消选择它并创建一个不带BOM(字节顺序标记)的文件(menu.inc.php)。

问候

rbo

If you use Dreamweaver, the preselected option for "source file creation" is:

use utf8 BOM [x]

deselect it and create a file (menu.inc.php) without the BOM (byte order mark).

Regards

rbo

Oo萌小芽oO 2024-09-21 06:26:19

Reeeeeeeee我知道已经晚了,但是这一小段 HTML 毫无困难地摆脱了它:

<meta charset="utf-8" />

希望它能帮助别人:)

Reeeeeeeeeally late I know, but this little piece of HTML got rid of it no trouble:

<meta charset="utf-8" />

Hope it helps someone :)

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