|
Comments for: galloway20021105.php3
| Message # 1014101: |
|
Date: 11/07/02 06:45
By: Danny Shepherd Profile Subject: Message Parsing Here's how I do my message parsing - no regexps so it could be a bit faster than the implementation shown here. <?php // Grab the entire message first. $stdin=fopen("php://stdin","r"); $message=$headerList=""; $headers=Array(); while (!feof($stdin)) $message.=fread($stdin,1024); fclose($stdin); // Make sure EOLs are \r\n $message=str_replace("\n","\r\n",$message); // Remove the single blank line at the top of the message // Don't know where this comes from (added by PHP at the stdin phase?) list(,$message)=explode("\r\n",$message,2); // Split the message into headers and body list($headerList,$message)=explode("\r\n\r\n",$message,2); // Make an array of headers (special handling for multiline headers) $headerList=explode("\r\n",str_replace("\r\n\t"," ",$headerList)); // Make an assoc array of headers // Note the extra param in explode()! foreach($headerList as $header) { list($key,$header)=explode(':',$header,2); $headers[strtolower($key)]=substr($header,1); } var_dump($headers); var_dump($message); ?><?php // Grab the entire message first. $stdin=fopen("php://stdin","r"); $message=$headerList=""; $headers=Array(); while (!feof($stdin)) $message.=fread($stdin,1024); fclose($stdin); // Make sure EOLs are \r\n $message=str_replace("\n","\r\n",$message); // Remove the single blank line at the top of the message // Don't know where this comes from (added by PHP at the stdin phase?) list(,$message)=explode("\r\n",$message,2); // Split the message into headers and body list($headerList,$message)=explode("\r\n\r\n",$message,2); // Make an array of headers (special handling for multiline headers) $headerList=explode("\r\n",str_replace("\r\n\t"," ",$headerList)); // Make an assoc array of headers // Note the extra param in explode()! foreach($headerList as $header) { list($key,$header)=explode(':',$header,2); $headers[strtolower($key)]=substr($header,1); } var_dump($headers); var_dump($message); ?> |
Previous Message | Next Message |
| Comments: | ||
| How to take online feedbak from user? | Anwarul | 06/10/05 07:24 |
| RE: Message Parsing | Bilal Farooq | 09/24/03 14:14 |
| RE: Mail Parsing - PEAR | montri | 01/25/03 08:57 |
| Mail Parsing - PEAR | Nil Angsioco | 12/09/02 19:52 |
| Mime Parser | Stephen VanDyke | 11/21/02 16:10 |
| Mime Parser | Stephen VanDyke | 11/21/02 16:10 |
| PHP Programming | Mahadi | 11/12/02 09:43 |
| RE: Message Parsing | Michael Galloway | 11/11/02 11:30 |
| Message Parsing | Danny Shepherd | 11/07/02 06:45 |
|
If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly. | ||


