Solved

Regular Expression Qestion - Reg Ex Question

Posted on 2014-01-04
3
407 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
  • 2
3 Comments
 
LVL 142

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 142

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 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