【问题标题】:Not encoding already encoded items with htmlentities不使用 htmlentities 对已编码的项目进行编码
【发布时间】:2010-01-28 20:43:18
【问题描述】:

我有一个看起来像这样的字符串:

Bürstner    

当我在其上使用 htmlentities() 时,我将 double encode 参数设置为 false,但它仍然最终将   重新编码为  

我用这个来编码:

$out = htmlentities($string,ENT_NOQUOTES, 0);

我是不是误解了它的工作原理?所需的输出是对元音变音 u 进行编码,但不考虑现有的 nbsp 实体(这只是一个示例,非常长文档中已经有许多实体)。

** 编辑 **

由于这似乎不清楚,原始字符串:

Bürstner   

期望的输出:

Bürstner   

现有的实体应该不理会。​​p>

【问题讨论】:

  • 您尝试过使用 htmlspecialchars 吗? us3.php.net/htmlspecialchars
  • htmlspecialchars 不编码变音符号
  • 你真的需要替换那些字符吗?你使用什么字符编码?

标签: php html


【解决方案1】:

htmlentities的第三个参数是charset参数;第四个参数是 double_encode 参数。所以试试这个:

$out = htmlentities($string, ENT_NOQUOTES, ini_get('default_charset'), false);

【讨论】:

    【解决方案2】:

    第三个参数是字符集;您需要将第四个而不是第三个设置为 false。

    【讨论】:

      【解决方案3】:

      htmlentities 的第 3 个参数是字符集。您需要将第 4 个参数设置为 false

      字符串 htmlentities ( 字符串 $string [, int $quote_style = ENT_COMPAT [, 字符串 $charset [, bool $double_encode = true ]]])

      http://www.php.net/manual/en/function.htmlentities.php

      【讨论】:

        【解决方案4】:

        在我看来你忽略了the third parameterhtmlentities()

        字符串 htmlentities (字符串 $string [, int $quote_style = ENT_COMPAT [, string $charset [, bool $double_encode = true ]]])

        试试

        $out = htmlentities($string, ENT_NOQUOTES, <whatever encoding you're using>, false);
        

        【讨论】:

          【解决方案5】:

          看看这个函数

          它的链接 http://php.net/manual/de/function.htmlspecialchars.php

          <?php
          function special_formatting($input) {
              $output = htmlspecialchars($input, ENT_QUOTES);
              $output = str_replace(array('  ', "\n"), array('&nbsp;&nbsp;', '<br>'), $output);
              return str_replace('&nbsp; ', '&nbsp;&nbsp;', $output);
          }
          ?>
          

          【讨论】:

            猜你喜欢
            • 2019-02-03
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-07-23
            • 2019-08-31
            • 1970-01-01
            • 2014-05-27
            • 1970-01-01
            相关资源
            最近更新 更多