How to replace - with – using php
How do i replace -
with –
using php htmlspecialchars()
$content = $_POST['content'];开发者_开发问答
You don't, -
is not a special character and as such will not be touched by htmlspecialchars()
. And -
is not even same as –
(- vs. –).
You can use str_replace()
if you want to:
$content = str_replace('-', '–', $_POST['content']);
htmlentities() will convert –
to –
(and take care of any other entities as well).
Just make sure you specify the correct character set, e.g.:
echo htmlentities($string, ENT_QUOTES, 'UTF-8');
精彩评论