du6029076877 2009-08-26 19:35
浏览 62
已采纳

PHP:删除不可打印的字符而不删除空格

I know this a common question but everything I found seems to remove white space.

I'm looking for a regular expression that will strip unprintable characters WITHOUT changing any whitespace. This a function that all user input will be filtered through, which means all the characters you could normally type on a keyboard are valid. Ex: the accents you see in Spanish are valid. Basically anything you could display using the UTF 8 charset.

Because this is SQL Server, I don't think the "SET NAMES UTF8" approach will work.

Here's what I have.

function stripNonPrintable($input) 
{
    return preg_replace('/[\x00\x08\x0B\x0C\x0E-\x1F]/', '', $input);
}
  • 写回答

2条回答 默认 最新

  • dtlc84438 2009-08-26 20:18
    关注

    Try something like this:

    function stripNonPrintable($input) {
       $bad=array(
          '\x00\x08\x0B\x0C\x0E-\x1F'
       );
       $fixed=array(
          ''
       );
       return str_replace($bad, $fixed, $input);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号