如何使用htmlentities对单引号进行编码

时间:2013-11-09 06:54:48

标签: php html-entities

            $string="A 'quote' is <b>bold</b>";
            echo $string;//output-->A 'quote' is bold

            $string=htmlentities($string, ENT_QUOTES, "UTF-8");
            echo $string;//output-->A 'quote' is <b>bold</b>

我的php版本是5.4.6

我想编码单引号和标记

1 个答案:

答案 0 :(得分:0)

尝试htmlspecialchars

<?php
$string="A 'quote' is <b>bold</b>";
echo $string."<br/>";//output-->A 'quote' is bold

$string=htmlentities($string, ENT_QUOTES, "UTF-8");
echo $string."<br/>";//output-->A 'quote' is <b>bold</b>

$string=htmlspecialchars($string);
echo $string."<br/>";          
?>