php 转换特殊字符为HTML实体字符

180it 2020-02-20 AM 318℃ 0条
/**
 * 转换特殊字符为HTML实体字符
 *
 * @param string $string
 * @param boolean $doubleEncode
 * @return string
 */
function htmlEncode($string, $doubleEncode = true)
{
    if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
        $reVal = htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', $doubleEncode);
    } else {
        $reVal = htmlspecialchars($string, ENT_QUOTES, 'UTF-8', $doubleEncode);
    }

    return $reVal;
}
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

php 转换特殊字符为HTML实体字符