#1 helloniu
class main extends spController
{
function index()
{
$this->display("index.html");
}
}
页面顶部没有空行显示出来
---------------------------------------------------------------------------------------------------
如果我加一行代码
class main extends spController
{
function index()
{
$sp=spClass("tbl_system");
//$id=$this->spArgs("id");
$sql="select * from tbl_system where id=1 ";
$this->rstop = $sp->findsql($sql);
$this->display("index.html");
}
}

这里就出现一行空白 模板文件我没添加任何smarty代码 请问这是什么原因啊 ? 怎么解决?
2010-12-10 15:39:48
#2 jake
应该是 tbl_system.php 这个model文件,里面有空格或者是UTF8带BOM,另存为UTF8不带BOM。然后再检查一下是否有空格在之外即可。
2010-12-10 15:46:03
#3 jake
如果有空行,一般会是某个文件输出了不可见字符,可以检查:
1. PHP文件和模板文件是否带了BOM,另存为UTF8无BOM即可。
2. PHP文件中是否有空格,检查一下是否有空格在之外。
3. 看看是否样式问题。(不过楼主的问题应该不是,因为加入新的代码才有的。)
4. 可以在$this->display("index.html");前面加上ob_clean();来避免,不过这是治标不治本。
2010-12-10 15:47:08
#4 helloniu
非常感谢jake 的及时回答
Google出清除BOM的php代码
操作步骤:
1.把代码copy到文本文档里
2.改名 任意文件名.php
3.打开浏览器,执行
http://localhost/111.php附代码:
//remove the utf-8 boms
//by magicbug at gmail dot com
if (isset($_GET['dir'])){ //config the basedir
$basedir=$_GET['dir'];
}else{
$basedir = '.';
}
$auto = 1;
checkdir($basedir);
function checkdir($basedir){
if ($dh = opendir($basedir)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..'){
if (!is_dir($basedir."/".$file)) {
echo "filename: $basedir/
$file ".checkBOM("$basedir/$file")."
";
}else{
$dirname = $basedir."/".
$file;
checkdir($dirname);
}
}
}
closedir($dh);
}
}
function checkBOM ($filename) {
global $auto;
$contents = file_get_contents($filename);
$charset[1] = substr($contents, 0, 1);
$charset[2] = substr($contents, 1, 1);
$charset[3] = substr($contents, 2, 1);
if (ord($charset[1]) == 239 && ord($charset[2]) == 187 &&
ord($charset[3]) == 191) {
if ($auto == 1) {
$rest = substr($contents, 3);
rewrite ($filename, $rest);
return ("
BOM found,
automatically removed.");
} else {
return ("
BOM found.
");
}
}
else return ("BOM Not Found.");
}
function rewrite ($filename, $data) {
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}
?>
2010-12-10 16:14:18