
String data
Function cleaner ($ mytext) (
/ / Clear out all non-Alpha-numeric characters
$ Mytext = ereg_replace ( "[^ A-Za-z0-9]", "", $ myText);
/ / Remove SPACES beginning and end
$ Mytext = trim ($ mytext);
return $ mytext
)
/ / Usage
$ String = "This is a text and numbers 12,345 and symbols !$%^&";
echo $ new_string
This PHP function with the first thing we do is, or regular expressions (regex), not mytext everything from variable $ is a capital or small letters away. This is in line with the statement "AZ" and "AZ" or "Exit". We are also having "0-9", the figures are also permitted. You can change this feature and remove the "0-9" and then the figures would serve as a complement to everything else away to remove it. Function, it would only uppercase and lowercase letters, not numbers.
The next step in the function will trim away the string that knows all of the leading and procedures / spaces from the string. Cutting Room of a string is very useful for data cleaning, users are not always aware of to put an extra place at the end of their contribution to the accident, so trim in these rooms is a good way to make it user friendly.
The last part of the function returns the statement, in which the function returns the value of the variable $ mytext after all data cleanup work has been applied.
By investing in a little time to learn Regular Expressions (regex), you can easily expand the function in much more detail and not the broad sword ", that it is now. You can easily change the function to search for a specific character, rather than" all but "the way I planned out.