【问题标题】:Output Buffering php producing nothing - why isn't this working?输出缓冲 php 什么也没产生 - 为什么这不起作用?
【发布时间】:2013-09-06 02:51:04
【问题描述】:

在 Joomla 模板文件 (index.php) 中,我试图获取在管理面板中设置的 2 个参数(然后包装在一些 css 格式中)来为 google 字体创建一些基本 css,然后将它们保存到单独的css 文件。也许我对此的想法都是错误的,但这是我正在尝试做的,但不用说它没有产生任何结果......

    <?php
      ob_start();
     ?>

        <?php echo $this->params->get('googleFont1types');?> {
        font-family: '<?php echo str_replace('+', ' ', $this->params->get('googleFont1'));?>', sans-serif;
        }
        <?php echo $this->params->get('googleFont2types');?> {
            font-family: '<?php echo str_replace('+', ' ', $this->params->get('googleFont2'));?>', serif;
        }"

     <?php
     $googlefontcss = ob_get_contents();
     ob_end_clean();
    file_put_contents('googlefonts.css', $googlefontcss);
     ?>

或者您知道更好的方法吗?我可以轻松地将样式内联编写为 css,如下所示(经过测试和工作) - 但理想情况下我不想要内联 css。我真的很想把这块 css 写到一个文本文件中。

  <?php
// Use of Google Font
if ($this->params->get('googleFont'))
{
?>
  <link href='http://fonts.googleapis.com/css?family=<?php echo $this->params->get('googleFont1');?>|<?php echo $this->params->get('googleFont2');?>' rel='stylesheet' type='text/css' />
  <style type="text/css">
    <?php echo $this->params->get('googleFont1types');?> {
      font-family: '<?php echo str_replace('+', ' ', $this->params->get('googleFont1'));?>', sans-serif;
    }
    <?php echo $this->params->get('googleFont2types');?> {
        font-family: '<?php echo str_replace('+', ' ', $this->params->get('googleFont2'));?>', serif;
    }
  </style>   

<?php
}
?>

【问题讨论】:

  • 什么是“什么都不生产?”你的 googlefonts.css 文件是可写的吗? var_dump($googlefontcss) 会得到什么?
  • 没有googlefonts.ss 我以为会默认创建? Vardump 给出这个字符串 (174) " h2, h3 { font-family: 'Bebas', sans-serif; } p { font-family: 'bitter', serif; }" "
  • 哪个猜测意味着我有权限问题而不是代码问题 - file_put_contents 不应该创建一个文件,即使它不存在?
  • 是的,如果它不存在就创建它。检查您的目录权限并查看它是否可写,因为看起来输出缓冲正在产生一些东西:)

标签: php xml parameters output output-buffering


【解决方案1】:

这是一个权限问题 - 现在已修复。感谢您的输入蒂姆

【讨论】:

    猜你喜欢
    • 2014-04-02
    • 2011-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-25
    • 2021-04-08
    相关资源
    最近更新 更多