About
Pricing
Community
Teams
Start Free Trial
Log in
SheppardDigital
asked on
11/16/2010
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-9
s]/", "", $string);
Thanks
PHP
5
1
Last Comment
david_coleman_007
8/22/2022 - Mon
Marco Gasi
11/16/2010
Try this:
$string = preg_replace("/[^a-zA-Z0-9
s][^-]/", "", $string);
Cheers
Samuel Liew
11/16/2010
$string = preg_replace("/[^a-zA-Z0-9s\-]/", "", $string);
Select all
Open in new window
Marco Gasi
11/16/2010
Ooops, I was confused! :-(
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
dsmile
11/16/2010
THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
david_coleman_007
11/16/2010
$string = preg_replace("/[^a-zA-Z0-9s\-]/", "", $string);
Select all
Open in new window
$string = preg_replace("/[^a-zA-Z0-9
Cheers