Solved

Regular Expression Qestion - Reg Ex Question

Posted on 2014-01-04
3
416 Views
Last Modified: 2014-01-04
Howdy!

Thanks for taking a look at this.  Can anyone tell me why this regular expression is removing spaces?  I think I've been staring at it for too long or something.

$myvar = preg_replace("/[^a-z\d.,-]/i", "", $myvar);

Thanks in advance!

ike1492
0
Comment
Question by:ike1492
[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
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39756478
yes, because the regular expression does removes all that is NOT alpha, decimal, dot, comma, dash.
if you don't want spaces to be removed, you have to add the space into the first part of the expression
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39756479
in code:

$myvar = preg_replace("/[^a-z\d\s.,-]/i", "", $myvar);
0
 

Author Closing Comment

by:ike1492
ID: 39756505
Glad it wasn't a snake! thanks very much!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

724 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