I need to write code that given a string, strips from it any of the following characters:
%, &, \, ", /, ?, ', <, >, :, *, |, ^, ,
(note that comma is also not permitted)
I know that I can achieve the following using this code
Code: Select all
$illegalCharacters = Array("%", "&", "\\", '"', "/", "?", "'", "<", ">", ":", "*", "|", "^", ",");
foreach ($illegalCharacters as $character) {
$text = str_replace($character, '', $text);
}Is there a better solution, one that possibly uses regular expression?
Note
I also need to strip the * and ? character
It is critical that their usage inside a regular expression will not lead to unexpected results,
stripping more characters than allowed, or missing a few ones from the list above
any help would be appreciated
thanks in advance