joomla 模块前的空格

发布于 2024-12-23 06:23:17 字数 359 浏览 2 评论 0原文

我目前正在开发一个自定义模块,由于某种原因,它在我输出的任何内容之前附加一个空格。 我的设置是这样的:

主类位于 helper.php 中, 逻辑在 mod_name .php 中, 输出位于 /tmpl/default .php

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

这是一个屏幕截图: 在此处输入图像描述

如果有人以前遇到过类似的情况,请告诉我,我将不胜感激!

I'm currently developing a custom module and for some reason it appends a blank space before anything I'm outputting.
My set up is like this:

main class is in helper .php,
logic is in mod_name .php,
output is in /tmpl/default .php

The strange thing is that if I have a method in my class that returns html. And then I call this method in my template everything's fine no extra lines are appended.
But if I try to write output, even plain text, in my template or mod_name.php I get this extra line.

Here's a screenshot:
enter image description here

Please let me know if anyone encountered anything like this before, I'd be much obliged!

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

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

发布评论

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

评论(4

请持续率性 2024-12-30 06:23:17

事实证明,问题是因为我包含了 2 个文件,每个文件都包含一个单独的类,出于某种原因,当我只包含 1 个文件时,一切正常。包含的文件没有空格,也没有生成任何输出,它只包含逻辑。
不过还是感谢您的时间和答复。

编辑:

最近再次偶然发现这个问题,结果发现没有 BOM 的 UTF-8 是可行的方法,但是 MVC 方面,请确保您的组件入口点“./com_helloworld/helloworld” .php”首先是没有 BOM 的 UTF-8!

Turned out that the problem was because I was including 2 files, each of them contained a separate class, for some reason when I was including only 1 file it all worked fine. The included file had no white-space and wasn't generating any output, it contained only the logic.
Thank You for your time and answers though.

EDIT:

Recently stumbled upon this issue again, turned out UTF-8 without BOM is the way to go, BUT MVC-wise, make sure that your components entry point "./com_helloworld/helloworld.php" is UTF-8 without BOM in the first place!

纵山崖 2024-12-30 06:23:17

无 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>

UTF-8 without BOM is the answer. I made 3 complex Joomla websites with conditional CSS to manage this problem before I found the cause.
I also found this script somewhere to put on the root of a Joomla website to recursively autosave UTF-8 no BOM php files.
It worked and saved me a lot of time:

<?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>
任谁 2024-12-30 06:23:17

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

I've encountered a similar problem today, and managed to solve it by encoding the module layout to "UTF-8 without BOM"

画骨成沙 2024-12-30 06:23:17

它看起来是一个保存的位置,用于设置隐藏的东西。我至少有时会在打印和 RSS 图标关闭的情况下发现这一点,但容器无法消失。如果您能找到源,您可以删除整个内容,或者在数据库文件中进行更正。看起来像某种注册模块,因此您可以在源文件中查找您可能拥有的任何模块(如果这听起来像这样)。抱歉,没有准确的答案,但希望能给您一点指导。

It looks to be a saved location for something set to hide. I at least have found this at times with print and rss icons turned off, but the container fails to go away. You can remove the whole thing, or make corrections in the database files if you can find the source. Looks like some sort of registration module so could you could look in the source files for any modules you might have like this if that rings a bell. Sorry not an exact answer, but hopefully gives a little direction.

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