简体   繁体   中英

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   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).

** 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; the fourth parameter is the double_encode parameter. 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.

The 3rd parameter of htmlentities is the charset.. you would need to set the 4th to 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

It seems to me that you overlooked the third parameter to htmlentities() :

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

<?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);
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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