使用PHP包含时如何避免空格? [英] How can I avoid the blank space when using PHP include?

查看:227
本文介绍了使用PHP包含时如何避免空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些文件需要包含在几个页面中,因此,我使用类似于

I have some files that I need to include in several pages so, I use something like

<html>
<head>
<title>This is a webpage</title>
</head>
<body>
<div>Hello, this is a webpage</div>
<?php include("header.html");?>
<div>Some more text.</div>
<?php include("BlockToInclude.php");?>
<div>Even more text.</div>
<?php include("footer.html");?>
</body>
</html>

问题在于每个 include(); 在包含的内容之前,我得到一个20px的空白区域。我通过将第一个包含的块的边距减少20px来解决这个问题,但我更喜欢避免这个空间而不是补偿它的东西。另外,我是PHP的新手,这是一种正常的行为,还是我应该找一些我做错的事?

The problem is that with each include(); I get a blank space of 20px before the included content. I get around this this by reducing the margin of the first included block by 20px, but I would prefer something that avoid this space instead of compensate it. Also, I'm kind of new to PHP, is this a normal behaviour or should I look for something I'm doing wrong?

更新:我检查了结果代码,在我调用 insert(); 函数的每个位置,它出现一个不在原始文件中的陌生人字符(也不是调用者或包含的)。我将代码从Firefox代码查看器(在哪里看不到)复制到我的编辑器(Windows中的RJ TextEd),它在框中显示为问号;如果我将此代码保存为静态html,则渲染相同,但如果我删除这些字符,则空格会消失。有什么想法吗?

UPDATE: I checked in the resulting code and in every spot where I called an insert(); function it appears an stranger character that is not in the original file (nor the caller or the included). I copied the code from the Firefox code viewer (where is not visible) to my editor (RJ TextEd in Windows) where it appears as a question mark in a box; if I save this code as an static html it renders the same, but if I delete those characters then the blank space disappears. Any thoughts?

推荐答案

我在这里找到了这个主题

I found this topic here

有人sais :

之前我遇到过这个问题。确保以ASCII而不是二进制文件上传文件。有时,对于某些FTP服务器,您必须手动设置它。还可以尝试在文本编辑器中将换行符转换为\ n。 Lemme知道你正在使用哪个编辑器,我会给你更具体的说明。

I've had this problem before. Make sure you upload your file in ASCII not Binary. Sometimes, with some FTP servers, you have to set this manually. Also try converting your newlines to "\n" in your text editor. Lemme know which editor you're using and I'll give you more specific instructions.

http://forums.digitalpoint.com/showthread.php?t=957679

还有人解决了它:
我用notepad ++解决了这个问题( http://notepad-plus.sourceforge.net/
使用notepad ++打开php文件,在格式菜单中选择不带BOM的utf-8编码并保存。

And someone solved it : I solve this problem using notepad++ (http://notepad-plus.sourceforge.net/) Open php files with notepad++ and in Format menu chose encode in utf-8 without BOM and save it.

希望这有助于

这篇关于使用PHP包含时如何避免空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆