PHP special character string filter

I need an all encompassing statement to remove all special characters, commas, and any other non url sype characters. Also id like it to turn all white spaces to _

an example would be

This is great, and easy too!!!----*_*_

to

This_is_great_and_easy_too

I also need to filter out any of the special odd characters that are sometimes generated
lexshineAsked:
Who is Participating?
 
TeRReFConnect With a Mentor Commented:
Okay, then you can do something like:

<?php

$s = 'This is great, and easy too!!!----*_*_';

$s = preg_replace(array('/[^a-z\d ]/is', '/\s+/s'), array('', '_'), html_entity_decode($s));

echo $s;

?>
0
 
lexshineAuthor Commented:
by special characters i mean this type of stuff:
’s
0
 
lexshineAuthor Commented:
an added bonus would be if the routine turned multiple spaces into one:

this     is too many spaces

this_is_too_many_space
0
 
TeRReFCommented:
Something like:

<?php

$s = 'This is great, and easy too!!!----*_*_';

$s = preg_replace(array('/[^a-z\d ]/is', '/\s+/s'), array('', '_'), $s);

echo $s;

?>
0
 
lexshineAuthor Commented:
very very nice!

what about dealing with stuff like. its encoded in some of the strings I am dealing with

Cindy&#39;s &quot;Road&quot; makes...

0
All Courses

From novice to tech pro — start learning today.