Remove chars from string using regex in php

From Code Trash

Jump to: navigation, search

Here is the regex to strip the characters you dont want to be in a string.
The following will remove all characters except letters numbers and spaces.
i is for case insensitive.

	echo preg_replace("/[^a-z0-9]+/i",'',"once @ , [ 87 aDF");
        echo preg_replace("/[^a-z 0-9]+/i",'',"once @ , [ 87 aDF"); // no remove spaces


and the output for the first reges is once87aDF

Personal tools
Google AdSense