From: germana on
i dont know if im gonna be wrong but, here i go:

you want to call to $_GET['email'] so in you URL should appear something
like this,

yourhost.com?email=bob(a)example.com

On Thu, 2008-01-17 at 12:29 +0000, Dan Stevens (IAmAI) wrote:

> Calling this code with the argument get=bob(a)example.com, I'd expect an
> interger output something like this
>
From: dan.stevens.iamai on
OK, I don't think I searched the web hard enough. I've not found a
definitive explanation, but I think the warning has something to do
with the dash symbols (\-) within the square brackets. Removing them -
changing them to the regular expression below - removes the warning

'^[a-zA-Z0-9_.]+@[a-zA-Z0-9]+\.[a-zA-Z0-9.]+$'

Question is now, how am I supposed to match dash symbols?

In one thread I read advised preg functions using the ereg functions.
I had ago with this, putting back in the dashes and changing the
regular expression to a perl RE:

'/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/'

No warnings this time and it appears to work. I still welcome any
feedback on ereg if anyone wants to give any.

On 17/01/2008, Dan Stevens (IAmAI) <dan.stevens.iamai(a)gmail.com> wrote:
> I'm have trouble with some code that I have been following in a book
> regarding regular expressions. I'm attempting to validate an email
> using a regular expression. Below is a simplified version of the code
> which reproduces the problem I'm having:
>
> <?php
> define("EMAIL_RE", '^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$');
> $email = trim($_GET['email']);
> $result = eregi(EMAIL_RE, $email);
> echo $result . "<br />\n";
> if ($result) echo "Email valid";
> else "Email invalid"
> ?>
>
> Calling this code with the argument get=bob(a)example.com, I'd expect an
> interger output something like this
>
> 15
> Email valid
>
> Yet instead, all get is a warning that I cannot fathom and nothing else:
>
> Warning: eregi() [function.eregi]: REG_ERANGE in C:\Documents and
> Settings\daniel.stevens\My
> Documents\Workspace\htdocs\tutoring\eregi_test.php on line 4
>
> I've tried searching for this warning to find out what it means, but I
> cannot find any reference to it on the web. Is anyone able to tell me
> what this warning means and why I am not getting the output I'm
> expecting? Can anyone advise how best to find out what a particular
> error or warning means so I don't have to ask on this list everytime I
> come across one that means nothing? php.net does not appear to have a
> list.
>
> Thanks in advance.
>
From: Niel Archer on
Hi

> OK, I don't think I searched the web hard enough. I've not found a
> definitive explanation, but I think the warning has something to do
> with the dash symbols (\-) within the square brackets. Removing them -
> changing them to the regular expression below - removes the warning
>
> '^[a-zA-Z0-9_.]+@[a-zA-Z0-9]+\.[a-zA-Z0-9.]+$'

> Question is now, how am I supposed to match dash symbols?

The problem is that you included the "\-" within SINGLE quotes. Escaping
a character only works within double quotes. Go back to your original
but substitute the ' for " around the expression. Like this:

define("EMAIL_RE", "^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$");

>
> In one thread I read advised preg functions using the ereg functions.
> I had ago with this, putting back in the dashes and changing the
> regular expression to a perl RE:
>
> '/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/'
>
> No warnings this time and it appears to work. I still welcome any
> feedback on ereg if anyone wants to give any.

--
Niel Archer
From: "Aaron Schiff" on
I think single quotes is right because you don't want PHP to escape
the characters...the escape is for regex, not PHP

On Jan 19, 2008 9:44 AM, Niel Archer <not(a)chance.now> wrote:
> Hi
>
> > OK, I don't think I searched the web hard enough. I've not found a
> > definitive explanation, but I think the warning has something to do
> > with the dash symbols (\-) within the square brackets. Removing them -
> > changing them to the regular expression below - removes the warning
> >
> > '^[a-zA-Z0-9_.]+@[a-zA-Z0-9]+\.[a-zA-Z0-9.]+$'
>
> > Question is now, how am I supposed to match dash symbols?
>
> The problem is that you included the "\-" within SINGLE quotes. Escaping
> a character only works within double quotes. Go back to your original
> but substitute the ' for " around the expression. Like this:
>
> define("EMAIL_RE", "^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$");
>
> >
> > In one thread I read advised preg functions using the ereg functions.
> > I had ago with this, putting back in the dashes and changing the
> > regular expression to a perl RE:
> >
> > '/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/'
> >
> > No warnings this time and it appears to work. I still welcome any
> > feedback on ereg if anyone wants to give any.
>
> --
> Niel Archer
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--
ts2do
From: Niel Archer on
> I think single quotes is right because you don't want PHP to escape
> the characters...the escape is for regex, not PHP

In fact, we're neither correct, I was thinking of PCRE, but this is
POSIX regexes which I'm not familiar with.
From the POSIX man pages:

"To include a literal `]' in the list, make it the first character
(following a possible `^'). To include a literal `-', make it the first
or last character, or the second endpoint of a range. To use a
literal `-' as the first endpoint of a range, enclose it in `[.' and `.]'
to make it a collating element (see below). With the exception of
these and some combinations using `[' (see next paragraphs), all other
special characters, including `\', lose their special significance
within a bracket expression"

Which seems to tell us it can't be (and doesn't need to be) escaped at
all. I'll stick with PCRE, they're binary safe.

I would try removing the backslash and moving the hyphen to be the last
character in the range (after the full stop).


> On Jan 19, 2008 9:44 AM, Niel Archer <not(a)chance.now> wrote:
> > Hi
> >
> > > OK, I don't think I searched the web hard enough. I've not found a
> > > definitive explanation, but I think the warning has something to do
> > > with the dash symbols (\-) within the square brackets. Removing them -
> > > changing them to the regular expression below - removes the warning
> > >
> > > '^[a-zA-Z0-9_.]+@[a-zA-Z0-9]+\.[a-zA-Z0-9.]+$'
> >
> > > Question is now, how am I supposed to match dash symbols?
> >
> > The problem is that you included the "\-" within SINGLE quotes. Escaping
> > a character only works within double quotes. Go back to your original
> > but substitute the ' for " around the expression. Like this:
> >
> > define("EMAIL_RE", "^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$");
> >
> > >
> > > In one thread I read advised preg functions using the ereg functions.
> > > I had ago with this, putting back in the dashes and changing the
> > > regular expression to a perl RE:
> > >
> > > '/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/'
> > >
> > > No warnings this time and it appears to work. I still welcome any
> > > feedback on ereg if anyone wants to give any.
> >
> > --
> > Niel Archer
> >
> >
> > --
> > PHP Windows Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
>
> --
> ts2do
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--
Niel Archer