Link to home
Start Free TrialLog in
Avatar of SheppardDigital
SheppardDigital

asked on

PHP preg_replace

Hi,

I currently have this line of code which cleans a string. Could someone tell me how I would change this to allow the minus sign (-)?

$string = preg_replace("/[^a-zA-Z0-9s]/", "", $string);

Thanks
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Try this:

$string = preg_replace("/[^a-zA-Z0-9s][^-]/", "", $string);

Cheers

$string = preg_replace("/[^a-zA-Z0-9s\-]/", "", $string);

Open in new window

Ooops, I was confused! :-(
ASKER CERTIFIED SOLUTION
Avatar of dsmile
dsmile
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of david_coleman_007
david_coleman_007

$string = preg_replace("/[^a-zA-Z0-9s\-]/", "", $string);

Open in new window