Re: regular expression
| From: | Red Wingate | Date: | Wed, 07 Apr 2004 11:03:14 +0000 |
| Subject: | Re: regular expression | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-182604@lists.php.net to get a copy of this message | ||
Alright,
first of all, in E-Mail Headers every param needs to be written in a
seperate line, therefore following will work even with multiple recipients:
$recipients = array();
$header = explode( "\n" , $header );
foreach ( $header AS $param ) {
$param = trim ( $param );
if ( strtolower( substr( $param , 0 , 3 ) ) == 'to:' ) {
$recipients[] = trim ( substr( $param , 3 ) );
}
}
This will match every of these:
'TO:foo@bar.com'
' TO: bar@baz.com'
' TO:Mr Baz <foo@bar.com>'
' TO:foo@bar.com,foo2@foobar.com,baz@foo.co.uk'
etc. pp
-- red
PS: I'm not sure about wether 'TO :' is allowed or not - sad thing :-)
Am Mittwoch, 7. April 2004 11:28 schrieb Simon Hayward:
> preg_match("/To: ([^<]+)<?([^>]+)?>?/i",$string,$matches);
>
> returns email in $matches[1] in the first instance
> and name in $matches[1] and email in $matches[2] in the second.
>
> -----Original Message-----
> From: Robert Kornfeld [mailto:aon.912628966@aon.at]
> Sent: 07 April 2004 09:32
> To: php-general@lists.php.net
> Subject: [PHP] regular expression
>
>
> hey, professionals out there:
>
> i need to write a parser for an email-header to retrieve the email of the
> 'To:'-field.
> there are 2 possibilities:
> 'To: foo@foo.com' or
> 'To: first foo <foo@foo.com>'
>
> i would only need the email-adress!
> does anyone know the regular expression that can handle both possibilities?
> (i give up!)
>
> thanx!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> Legal Disclaimer:-
>
> Internet communications are not secure and therefore the
> Barclays Group does not accept legal responsibility for the
> contents of this message. Although the Barclays Group
> operates anti-virus programmes, it does not accept
> responsibility for any damage whatsoever that is caused
> by viruses being passed. Any views or opinions presented
> are solely those of the author and do not necessarily
> represent those of the Barclays Group.
>
> Replies to this e-mail may be monitored by the Barclays
> Group for operational or business reasons.
>
> Barclays Bank PLC trading as "Shopsmart from Barclaycard".
> Registered Office: 54 Lombard Street
> London EC3P 3AH
> Registered in England, Registration No. 1026167.