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) "• Red
• Green
• Blue<br />"
I assumed passing false
to the double_encode parameter would prevent <br />
from being converted to <br />
.
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;
won't happen.
The double_encode
parameter prevents encoding existing html entities (e.g. •
). <br />
is not an html entity, so it gets encoded.
精彩评论