Hello I am using following code to allow characters like A to Z and numeric values like 0 to 9. $result = preg_replace('/[^a-zA-Z0-9_]/', '', $result); In case allow only numeric values I use $result = preg_replace("[^0-9]","", $string); Actually I need preg_replace to allow A-Z plus 0-9 and some special characters like < > / @ & and white spaces. Is there any way in preg_replace to do so? Any help please? Thanks!
Perhaps it´s easier than you think: $result = preg_replace("/[^!<>@&\/\sA-Za-z0-9_]/","", $string); PHP: just put the chars you want to not remove in the [] and you be fine. You have to escape the / with \/ otherwise it will change the regex.