繁体   English   中英

不使用htmlentities编码已编码的项目

[英]Not encoding already encoded items with htmlentities

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

Bürstner    

当我对它使用htmlentities()时,我将double encode参数设置为false,但它仍然会重新编码  进入 

我用它来编码:

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

我在某种程度上误解了这是如何工作的? 所需的输出是对变音符号u进行编码,但仅保留现有的实体(这只是一个例子,已经在很长的文档中有很多实体)。

**编辑**

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

Bürstner   

期望的输出:

Bürstner   

应该保留现有实体。

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

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

第三个论点是字符集; 你需要将第四个而不是第三个设置为false。

htmlentities的第三个参数是charset ..你需要将4th设置为false

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

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

在我看来,你忽略 htmlentities() 的第三个参数

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

尝试

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

看看这个功能

它的链接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);
}
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM