Forum Moderators: coopster

Message Too Old, No Replies

regexp question dealing with '

I tried ereg eregi

         

aceskull

2:52 am on Apr 16, 2004 (gmt 0)

10+ Year Member



hi guys, I am trying to check US City names using ereg and I have tried eregi also. the only problem is when i get a submit that has a ' for instance O'Hare the ' gets rejected and the out puts a slash next to the '.

here is the code for the city check

if(!(ereg("^([[:alpha:]]+([.¦-]?[[:space:]]?[[:alpha:]]+){2,})$", $_SESSION["city"])))
{
//do what I want here
}

the whole code is on one line and it works perfect but when I change the code to this...

if(!(ereg("^([[:alpha:]]+([\\'¦.¦-]?[[:space:]]?[[:alpha:]]+){2,})$", $_SESSION["city"])))
{
//whatever I want goes here
}
the code doesn't work and the output is displayed like this......

O\' Hare

i tried removing the slashes with the stripslashes to the output, but that just fixes the output but I still go in the if statement. I tried it with only one slash as well but same result. What am I doing wrong. why can't I escape ' should I use something else other than ereg or eregi. Thanks in advance for your help.

coopster

7:34 pm on Apr 16, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You mentioned that you get a "submit" so I am assuming that the data that you are placing in the
$_SESSION['city']
variable is coming from <form> data. Are you familiar with PHP's magic quotes? The slash is probably already there from the submitted form data, meaning the city may already be quoted. The example on this page may help: get_magic_quotes_gpc [php.net]

If this is the case, why not stripslashes prior to edit-checks?

aceskull

11:09 pm on Apr 16, 2004 (gmt 0)

10+ Year Member



Oh man, I totally forgot about it. thanks for being my 2nd brain.

It works.........;)