preg_replace

what do i change so my preg_replace allows spaces too?  At the mo, it allows letters a-z upper and lower and numbers 0-9... but i need to keep spaces...

preg_replace('/[^a-z0-9]/i','',$string);
LVL 16
ellandrdAsked:
Who is Participating?
 
RoonaanConnect With a Mentor Commented:
Add a space into your regexp:

preg_replace('/[^a-z0-9 ]/i','',$string);

-r-
0
 
ellandrdAuthor Commented:
oh its as simple as that?
0
 
RoonaanCommented:
Yes :-)

The block-anchors define a set of characters [a-z] matches all alpha's, [a-z ] al alpha's and spaces.

By using [^ instead of [ you can match all characters but the ones inside the [].

So [^a-z0-9 ] matches all but alphanumerics and spaces.

-r-
0
 
ellandrdAuthor Commented:
Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.