Solved

preg_replace

Posted on 2006-07-21
4
666 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
  • 2
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 500 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now