dtgr3392 2012-06-05 12:19
浏览 69
已采纳

编写适用于任何语言的php函数

I'm writing a function to clear text which works with or without ut8 characters.

I keep getting text like this.

Coventry Salary - �25,000 - �35,000 

but with this function it removes the � but leaves other.

I want to know if anyone wrote a function which cleans the text.

function convertHTMLSpecialChars ( $str='' ) 
{
    $str = htmlspecialchars ( $str );
    $str = mb_convert_encoding($str, 'UTF-8', mb_detect_encoding($str));
    $str = htmlspecialchars($str, ENT_NOQUOTES, 'UTF-8');
    return $str;
}
  • 写回答

2条回答 默认 最新

  • doutian3010 2012-06-05 12:25
    关注

    this function:

    $str = mb_convert_encoding($str, 'UTF-8', mb_detect_encoding($str));
    

    just tries to detect the character set from $str; if it finds that $str contains utf8 characters it will return "utf8" so the func will be actually:

    $str = mb_convert_encoding($str, 'UTF-8', 'UTF-8');
    

    which doesnt help much.. in my opinion you should give the character set of your string by hand. for example, if its turkish: iso-8859-5, if its greek: iso-8859-7 and so..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度