I am using this code: $menu_css = ereg_replace("[^A-Za-z0-9]", "", $menu_css ); Code (markup): However, the code is removing spaces. How can I change it so that it removes everything, except spaces?
if you remove everything except spaces then you end up with a string containing only spaces! What is the point of that? Maybe you should explain more what you want to do.
The code above only removed everything that is not a number or letter. However, it is also removing spaces. I do not want it to remove spaces. I don't want it to remove underscores either. Or, in other words, I want to remove everything except numbers, letters, spaces and underscores from $my_value.
Try this. $string = 'Some 1234 very big string _ with - space .'; $allowed = "/[^a-z0-9\\ \\_\\\\]/i"; $result_string = preg_replace($allowed,"",$string); Code (markup):