无效字符替换为空格

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 ?

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);

you can do it via using preg_replace() function

<?php 
  $someone = "Hel#o wor*d";
  echo  preg_replace('/[\s\W]+/',' ',$someone); 
 ?>

Output -

Hel o wor d