开发者

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜