dongqiao6730 2014-05-07 16:31
浏览 35

删除字符串中的特殊字符[关闭]

I am currently doing this:

$a = 'some string with special characters';
$a = htmlentities($a);
$a = trim(preg_replace('/&#?[a-z0-9]+;/i', '', $a));

This works but I am wondering if there's a more efficient way to do this?

  • 写回答

1条回答 默认 最新

  • douyou1857 2014-05-07 16:37
    关注

    it contains certain characters like  and I want to remove those.

    Try utf8_decode, or more feature-filled:

    $output = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $input);
    

    Documentation

    The reason I bring this up is because what you are seeing are encoding issues, not "special characters".

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 C# datagridview 栏位进度