开发者

htmlentities()'s double_encode parameter not behaving correctly?

Hey guys, I'm trying to use htmlentities() to convert the characters in a textarea to html codes. The code I have right now looks like this:

 var_dump($colors);
 $c开发者_开发问答olors= htmlentities($colors, ENT_QUOTES, 'UTF-8', false);
 var_dump($colors);

which returns this:

    string(31) "• Red 
    • Green
    • Blue<br />"
    string(46) "&bull; Red 
    &bull; Green
    &bull; Blue&lt;br /&gt;"

I assumed passing false to the double_encode parameter would prevent <br /> from being converted to &lt;br /&gt;.

Any ideas?


Sounds like you want a "\n" instead of a <br /> inside your textarea.

To automate this from your data, you could do...

$colors = preg_replace('/<br\s?\/?>/', "\n", $colors);

Double encode just means things like &amp;amp; won't happen.


The double_encode parameter prevents encoding existing html entities (e.g. &bull;). <br /> is not an html entity, so it gets encoded.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜