Removing unwanted characters on String using PHP

Remove unwanted characters using PHP

Use this php code to remove unwanted characters on your input content.

(a) Remove Non-numerical characters


(b) Remove Non-alphabetic characters


(c) Remove non-alphanumeric characters


(d) Remove white_space only


Notes: syntax => preg_replace(expression,replace_content,variable);
1.Some Expressions are,
“/[0-9]/” or “/ \d/ g” => Select digits only
“/[^0-9]/” or “/ \D /g” => Select all non-digits
“/[a-zA-Z]/” => Select Alphabetics only
“/[^a-zA-Z]/” or “/ \D /g” => Select all non-alphabetics
“/[a-zA-Z0-9]/” or “/ \D /g” => Select all Alpha-numeric characters
“/[^a-zA-Z0-9]/” or “/ \D /g” => Select all Non-alphanumeric characters
2.Replace_Content => you can add any variable type as a replace content include white-space(” “) and empty field(“”).
3.Variable => You can use any assigned variable or direct values

Leave a Reply

%d bloggers like this: