Hello,
I am desperately trying to write a preg_replace function to strip the symbols;
* ^ & ' " ( ) % $ £
out of a string
Can anyone help?
Thanks
Dave
preg_replace certain symbols
Moderator: General Moderators
an entire forum dedicated to regex we have. Posted in there this should have been.
reserved are most of those symbols, so escape them you must using "\".
ex:
reserved are most of those symbols, so escape them you must using "\".
ex:
Code: Select all
$pattern = "#\*#";- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Like Burr says... just escape them since most of them are reserved. Single characters *might* be easier to do with str_replace()
Moved to regex 
Code: Select all
$bad = array (
'/\\*/',
'/\\^/',
'/&/',
'/\\\'/',
'/\\"/',
'/\\(/',
'/\\)/',
'/\\%/',
'/\\$/',
'/£/'
);
$new_string = preg_replace($bad, '', $string);