简体   繁体   English

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

[英]Not encoding already encoded items with htmlentities

I have a string that looks something like this: 我有一个看起来像这样的字符串:

Bürstner    

When I use htmlentities() on it, I set the double encode param to false, but it still ends up re-encoding the   当我对它使用htmlentities()时,我将double encode参数设置为false,但它仍然会重新编码  into   进入 

I'm using this to encode: 我用它来编码:

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

Am I somehow misunderstanding how this works? 我在某种程度上误解了这是如何工作的? The desired output is to encode the umlaut u, but leave the existing nbsp entities alone (this is just an example, there are MANY entities in a very long document already). 所需的输出是对变音符号u进行编码,但仅保留现有的实体(这只是一个例子,已经在很长的文档中有很多实体)。

** EDIT ** **编辑**

Since this seems unclear, ORIGINAL STRING: 由于这似乎不清楚,原始字符串:

Bürstner   

DESIRED OUTPUT: 期望的输出:

Bürstner   

The existing entities should be left alone. 应该保留现有实体。

The third parameter of htmlentities is the charset parameter; htmlentities的第三个参数是charset参数; the fourth parameter is the double_encode parameter. 第四个参数是double_encode参数。 So try this: 试试这个:

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

The third argument is the charset; 第三个论点是字符集; you need to set the fourth, not the third, to false. 你需要将第四个而不是第三个设置为false。

The 3rd parameter of htmlentities is the charset.. you would need to set the 4th to false htmlentities的第三个参数是charset ..你需要将4th设置为false

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

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

It seems to me that you overlooked the third parameter to htmlentities() : 在我看来,你忽略 htmlentities() 的第三个参数

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

try 尝试

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

Have a look at this function 看看这个功能

The link for it http://php.net/manual/de/function.htmlspecialchars.php 它的链接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