Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

preg_replace

Posted on 2006-07-21
4
Medium Priority
?
685 Views
Last Modified: 2008-02-26
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);
0
Comment
Question by:ellandrd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 2000 total points
ID: 17153111
Add a space into your regexp:

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

-r-
0
 
LVL 16

Author Comment

by:ellandrd
ID: 17153114
oh its as simple as that?
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 17153123
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
 
LVL 16

Author Comment

by:ellandrd
ID: 17153132
Thank you!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question