2011-12-30 36 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>