[kwlug-disc] PHP, email addresses and regular expressions

Robert P. J. Day rpjday at crashcourse.ca
Tue Mar 30 15:36:31 EDT 2010


On Tue, 30 Mar 2010, Chris Bruner wrote:

> Robert P. J. Day wrote:
> >   i want to write a PHP function that takes a moderately sane email
> > address and breaks it into its components and returns those pieces as
> > an array.  there are only two possibilities i will accept:
> >
> >   full addresses:  "Robert P. J. Day <rpjday at crashcourse.ca>"
> >   short addresses: rpjday at crashcourse.ca
> >
> > what i want to get back is, in both cases above, the first two
> > elements of the array being the username ("rpjday") and domain
> > ("crashcourse.ca"), and *then*, in the full case, the third element of
> > the array will be the full name ("Robert P. J. Day").  on totally
> > invalid email address, NULL shall be returned.
> >
> >   in a few minutes, i lashed together the following:
> >
> > =====
> >
> You might want to look at explode.
> I think you can do something like
> array = explode("'<>@",instring);
>
> and you will get an array of the instring divided into parts separated by the
> elements of "<>@", after that, just rearrange and return what you want.

 no, i think that delimiter argument is taken literally, but suddenly,
i am reminded of preg_split(), which might do the equivalent.

rday
--

========================================================================
Robert P. J. Day                               Waterloo, Ontario, CANADA

            Linux Consulting, Training and Kernel Pedantry.

Web page:                                          http://crashcourse.ca
Twitter:                                       http://twitter.com/rpjday
========================================================================




More information about the kwlug-disc mailing list