PHP string (PREG?) how to replace several punctuation chars with space

is there an easy single call to a function that could replace the any  non alphanumeric  with a simple space

thus the following...  
the,quick.brown:fox!jumped%over(the*lazy#etc2
 would yield
the quick brown fox jumped over the lazy etc2

thanks
willsherwoodAsked:
Who is Participating?
 
gamebitsConnect With a Mentor Commented:
$filename = "the,quick.brown:fox!jumped%over(the*lazy#etc2";

$illegalchars_type_1 = array(".",'"',":","%","!","*","#","|"," ",",");

$filename = str_replace($illegalchars_type_1,"_",$filename);

echo "$filename";
0
 
gamebitsCommented:
Sorry should be this

$filename = str_replace($illegalchars_type_1," ",$filename);
0
 
TedInAKConnect With a Mentor Commented:
This is from http://newsourcemedia.com/blog/php-remove-non-alphanumeric-characters/

<?php

$string = Here! is some text, and numbers 12345, and symbols !£$%^&;

$new_string = preg_replace(/[^a-zA-Z0-9\s]/, , $string);

echo $new_string

?>
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
willsherwoodAuthor Commented:
thanks all!
0
 
TedInAKCommented:
Whoops...try this instead:
<?php

$string = Here! is some text, and numbers 12345, and symbols !£$%^&;

$new_string = preg_replace(/[^a-zA-Z0-9\s]/, " " , $string);

echo $new_string

?>

Open in new window

0
 
willsherwoodAuthor Commented:
thanks i assumed quotes for BOTH parameters - they are hidden in your original message

thanks again
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.