2012-03-18 48 views
1

メールファイルの先頭を解析する(Content-Typeの:ファイルの内容読んで、私は(ヘッドのみ)</p> <p>私はこの線に読み出さたい</p> <p>iは、メールファイルの先頭を読み出し/解析したいメールファイルを持っている

Received: from [41.43.66.49] by web121206.mail.ne1.yahoo.com via HTTP; Thu, 15 Mar 2012 03:01:18 PDT 
X-Mailer: YahooMailWebService/0.8.117.340979 
References: <[email protected]> 
Message-ID: <[email protected]> 
Date: Thu, 15 Mar 2012 03:01:18 -0700 (PDT) 
From: Black Dream <[email protected]> 
Reply-To: Black Dream <[email protected]> 
Subject: Need help installing your certificate? 
To: "[email protected]" <[email protected]> 
In-Reply-To: <[email protected]> 
MIME-Version: 1.0 
Content-Type: multipart/mixed; boundary="1735753853-309369511-1331805678=:39182" 

--1735753853-309369511-1331805678=:39182 
Content-Type: multipart/alternative; boundary="1735753853-307665870-1331805678=:39182" 

--1735753853-307665870-1331805678=:39182 
Content-Type: text/plain; charset=iso-8859-1 
Content-Transfer-Encoding: quoted-printable 

=0A=0A=0A----- Forwarded Message -----=0AComodo Group, Inc. <e-mail= ..... 
.... hello hello hello ... the message body here 

、ここでiは

に取り組んコードであるため)、これはヘッドここ

の終わりは一例です

$the_mail_data = array(); 
$handle = fopen('mail.txt', 'r'); 
while (($buffer = fgets($handle)) !== false) { 
     $break = explode (':' , $buffer); 
     $the_mail_data[$break[0]] = $break[1]; 
     if ($break[0] == 'Content-Type') 
     break; 
} 
fclose($handle); 
    //Now i've the data in this array $the_mail_data(); 
    //print_r ($the_mail_data); 
    //echo $the_mail_data['subject']; 

コードはうまく機能していますが、私はより速いものが必要です!

は、いずれも速い機能または高速なコードを持っていますか?

私は今(のfile_get_contentsを)しようとしています、それはだが速いようだが、それはすべてのファイルを読んで、私はあなたがファイルを分割するために、シェルからSEDを使用して最速の結果を得る可能性がありますファイル

答えて

0

の一部を読み取ることができません二つの部分のContent-Typeの文字列に基づいて、その後、バックシステムコマンドからの結果を得るには:

$head = system("sed '1,/^Content-Type$/!d' < mail.txt"); 

あなたのmail.txtファイルへのフルパスをおそらく必要があります。それを試して速度を比較してください。

+0

ありがとうございますが、あなたのコマンドは一部だけでなくすべてのメッセージファイルに読み込まれています! –

+0

file_get_contents:0.0002秒でページが生成されました。 Sedコマンド:0.0054秒でページが生成されました。 あなたは冗談ですか? –

+0

このコマンドは、ファイル全体を読み取り、前半を出力として返す必要があります。私はそれが速くなるかどうかわからなかった。どうやらない。 – davidethell

関連する問題

 関連する問題