Remove special characters except white spaces

Below code will remove all special charaters except white spaces, For example, is we input a string “Hello vijaya#$%kumar&%”, it will returns string as “Hello vijayakumar”. I hope it will useful for some programmers, easy to implement. Try this and comment.

<?php

function alphanumericAndSpace( $string )

{

return preg_replace(‘/[^a-zA-Z0-9\s]/’, ”, $string);

}

?>

You can leave a response, or trackback from your own site.

Leave a Reply