I\'m pretty new to PHP, and I noticed there are many different ways of handling regular expressions.
This is what I\'m currently using:
$replace = ar
$newString = preg_replace('/[^a-z0-9]/i', '_', $join);
This should do the trick.
The easiest way is this:
preg_replace('/\W/', '_', $join);
\W is the non-word character group. A word character is a-z, A-Z, 0-9, and _. \W matches everything not previously mentioned*.
Edit: preg uses Perl's regular expressions, documented in the perlman perlre document.
*Edit 2: This assumes a C or one of the English locales. Other locales may have accented letters in the word character class. The Unicode locales will only consider characters below code point 128 to be characters.
The regular expression for anything which isn't a-z, A-Z, 0-9 is:
preg_replace('/[^a-zA-Z0-9]/', "_", $join);
This is known as a Negated Character Class