Hi, I am wondering if there a build-in fuction that take a string as input and then replace every non-numbers, non-alphabet characters with "_" (underscore)? Eg: yes? or no! will be converted to yes__or_no (i will use it as part of the URL) I guess regular expression can do the trick? Would anyone please give me the codes? Thanks.
Try a preg_replace to do it. Something like: $new_string = preg_replace("/\W/s","_",$string); or $new_string = preg_replace("/[^a-Z0-9]+/","_",$string);
Thanks for the reply. the first solution works, but the second one doesnt. Warning: preg_replace() [function.preg-replace]: Compilation failed: range out of order in character class at offset 4