SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Mar 31, 2006, 22:14 #1
- Join Date
- Feb 2004
- Location
- United States
- Posts
- 98
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Regular Expressions, stripping everything but letters, spaces, and digits
How do I go about removing everything in a string besides letters, spaces, and digits?
So far I have
$newvar = ereg_replace("[^A-Za-z0-9]", "", $string);
That takes care of the letters and digits, but not the spaces.
Help?
-
Mar 31, 2006, 22:50 #2
- Join Date
- Dec 2005
- Posts
- 37
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
spaces:
\s //any whitespace spaces, new lines tabs
try thatNeed any video services done? PM me
Watermarking, Thumbnails, Video Content Submission,
Encoding videos including Flash (.flv).
-
Mar 31, 2006, 22:51 #3
- Join Date
- Feb 2004
- Location
- United States
- Posts
- 98
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I have tried things like
$newvar = ereg_replace("[^A-Za-z0-9\s]", "", $string);
but that hasn't worked
-
Apr 1, 2006, 00:09 #4
- Join Date
- Feb 2006
- Posts
- 8
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
try to use trim() to remove spaces
-
Apr 1, 2006, 00:59 #5
- Join Date
- Mar 2001
- Posts
- 3,537
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That takes care of the letters and digits, but not the spaces.
2) Shortcuts for character classes don't work with ereg(), e.g. \s.
3) A space is represented by? How about......a space!
Code:$regex ="/[^0-9a-zA-Z ]/"; ^ $str = "a-A&a 9-8,7*6 b B b"; echo preg_replace($regex, "", $str);
Bookmarks