dongliqian6245 2012-11-20 06:41
浏览 115
已采纳

无效字符替换为空格

I'm currently trying to filter alphanumeric characters only. Therefore, I've tried a following Zend Function,

$filter = new Zend_Filter_Alnum(array('allowwhitespace' => true));
$return = $filter->filter('This is (my) content: 123');

This actually amazing but the issue is here I need to replaced the characters with white space. For example if I enter "Hel#o wor*d" it has to be "Hel o wor d". Aslo I've tried php str_replace function it's actually good but I've to define there a loads of invalid characters. Could any please tell me how to do this easily ?

  • 写回答

2条回答 默认 最新

  • dqyuipw44576 2012-11-20 08:14
    关注

    You can create a custom filter for that Writing Custom Filters

    ** For your requirement copy the Zend Alphanumeric fiter (Zend_Filter_Alnum) and replace preg_replace($pattern, '', (string) $value); (line 144) to
    preg_replace($pattern, ' ', (string) $value);

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

报告相同问题?