Jump to content

preg_match help


afrojojo

Recommended Posts

I am trying to search an email header for the email address after it was piped to the script.

 

This is what the header and code look like:

 

Header

From [email protected] Sun Feb 14 17:45:41 2010

 

Code

if (preg_match("/^From (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}

 

Outputs "[email protected] Sun Feb 14 17:45:41 2010"

 

I want it to output just "[email protected]"

 

Any Ideas?

Link to comment
https://forums.phpfreaks.com/topic/192089-preg_match-help/
Share on other sites

What if the header looks like this and is in an $email variable:

 

Header

From [email protected] Mon Feb 15 11:34:42 2010 Received: from xx-xx-xx-xx.dhcp.eucl-nbb.wi.charter.com ([xx-xx-xx-xx] helo=[xx-xx-xx-xx]) by xx.xx.com with esmtpa (Exim 4.69) (envelope-from ) id 1Nh5mL-00035o-Ti for rsv

 

Code

if (preg_match("/^From (\S+)/", $email[$i], $matches)) {
$from = $matches[1];
}

 

It doesn't output anything. I want it to output "[email protected]".

Link to comment
https://forums.phpfreaks.com/topic/192089-preg_match-help/#findComment-1012739
Share on other sites

If your not sure where it's from, why is it there? Of course it doesn't output anything, hence the fact I had the big fat if at the start of my post. If $email contains the header then it should be...

 

if (preg_match("/^From (\S+)/", $email, $matches)) {
   $from = $matches[1];
}

Link to comment
https://forums.phpfreaks.com/topic/192089-preg_match-help/#findComment-1012752
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.