2011-12-30 65 views
1

我目前正在开发一个自定义模块,并且出于某种原因,它会在我输出任何东西之前追加一个空格。 我的设立是这样的:joomla模块之前的空白处

主类是辅助性.PHP, 逻辑是mod_name .PHP, 输出是/ TMPL /默认.PHP

奇怪的是,如果我有我的类中返回html的方法。然后我在我的模板中调用这个方法一切正常,没有额外的行被添加。 但是,如果我尝试写我的模板或mod_name.php输出,甚至纯文本,我得到这个额外的行。

以下是截图: enter image description here

请让我知道,如果没有人遇到这样的事情之前,我会非常感激!

回答

3

原来,这个问题是因为我包括2个文件,每个文件的他们包含一个单独的类,出于某种原因,当我只包含1个文件时,它们都运行正常。包含的文件没有空格,并且没有生成任何输出,它只包含逻辑。 谢谢您的时间和答案。

编辑:

近日偶然发现了这个问题再次横空出世,UTF-8无BOM是要走的路,但MVC明智的,请确保您的组件入口点” ./com_helloworld/ helloworld.php“是首先没有BOM的UTF-8!

+0

是的,无法想象我的自我一段时间......不知何故文件编码是添加一个空格,并用双引号括起来“” 适用于组件...... – petsoukos 2012-07-22 18:15:45

0

它看起来是被隐藏的东西的保存位置。我至少在打印和rss图标关闭的时候发现了这种情况,但是容器未能消失。如果可以找到源文件,您可以删除整个文件,或者修改数据库文件。看起来像某种注册模块,所以你可以在源文件中查找任何你可能喜欢的模块。对不起,没有一个确切的答案,但希望给一个小方向。

+0

我知道你在说什么,但我用我自己的自定义模板,因此所有这些隐藏的“申报单”已被删除。 – michaeltintiuc 2012-02-06 12:42:56

1

今天我遇到了类似的问题,并设法通过编码模块布局“UTF-8无BOM”来解决这个问题

2

没有BOM的UTF-8就是答案。在找到原因之前,我使用条件CSS制作了3个复杂的Joomla网站来管理此问题。 我也发现这个脚本放在Joomla网站的根目录上,递归地自动保存UTF-8没有BOM php文件。 它的工作,并为我节省了大量的时间:

<?php 
// Tell me the root folder path. 
// You can also try this one 
// $HOME = $_SERVER["DOCUMENT_ROOT"]; 
// Or this 
// dirname(__FILE__) 
$HOME = dirname(__FILE__); 
// Is this a Windows host ? If it is, change this line to $WIN = 1; 
$WIN = 0; 

// That's all I need 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>UTF8 BOM FINDER and REMOVER</title> 
<style> 
body { font-size: 10px; font-family: Arial, Helvetica, sans-serif; background: #FFF; color: #000; } 
.FOUND { color: #F30; font-size: 14px; font-weight: bold; } 
</style> 
</head> 
<body> 
<?php 
$BOMBED = array(); 
RecursiveFolder($HOME); 
echo '<h2>These files had UTF8 BOM, but i cleaned them:</h2><p class="FOUND">'; 
foreach ($BOMBED as $utf) { echo $utf ." 
\n"; } 
echo '</p>'; 

// Recursive finder 
function RecursiveFolder($sHOME) { 
    global $BOMBED, $WIN; 

    $win32 = ($WIN == 1) ? "\\" : "/"; 

    $folder = dir($sHOME); 

    $foundfolders = array(); 
    while ($file = $folder->read()) { 
    if($file != "." and $file != "..") { 
     if(filetype($sHOME . $win32 . $file) == "dir"){ 
     $foundfolders[count($foundfolders)] = $sHOME . $win32 . $file; 
     } else { 
     $content = file_get_contents($sHOME . $win32 . $file); 
     $BOM = SearchBOM($content); 
     if ($BOM) { 
      $BOMBED[count($BOMBED)] = $sHOME . $win32 . $file; 

      // Remove first three chars from the file 
      $content = substr($content,3); 
      // Write to file 
      file_put_contents($sHOME . $win32 . $file, $content); 
     } 
     } 
    } 
    } 
    $folder->close(); 

    if(count($foundfolders) > 0) { 
    foreach ($foundfolders as $folder) { 
     RecursiveFolder($folder, $win32); 
    } 
    } 
} 

// Searching for BOM in files 
function SearchBOM($string) { 
    if(substr($string,0,3) == pack("CCC",0xef,0xbb,0xbf)) return true; 
    return false; 
} 
?> 
</body> 
</html>