0

$open_email_msg を検索するスクリプトを取得しようとしていますが、電子メールによって情報は異なりますが、以下と同じ形式になります。Title: または Tags: または Categories: の後に置くものは何でも欲しいだけです。そのデータがキャプチャされるものは何でも、文字列 "Title:" または "Tags:" または "Categories:" ではありません これはコード全体の単なるスニペットです。残りは情報を MySQL テーブルに挿入し、サイトのニュース記事に投稿します。

誰かがこれに対する解決策を見つけるのを手伝ってくれますか?

厳密な電子メール メッセージ形式:

ニュース更新の
タイトル: 記事のタイトル
タグ: tag1 tag2
カテゴリ: 記事のカテゴリ、2 番目の記事のカテゴリ
スニペット: 記事のスニペット。
メッセージ: 記事のメッセージ。画像。より多くのテキスト、より多くのテキスト。Lorem impsum dolor sit amet.

<?php
//These functions searches the open e-mail for the the prefix defining strings.
    //Need a function to search after the space after the strings because the subject, categories, snippet, tags and message are constant-changing.
$subject = strpos($open_email_msg, "Title:");       //Searches the open e-mail for the string "Title" 
$categories = strpos($open_email_msg, "Categories:");       //Searches the open e-mail for the string "Categories"
$snippet = strpos($open_email_msg,"Snippet");           //Searches the open e-mail for the string "Snippet"
$content = strpos($open_email_msg, "Message");  //Searches the open-email for the string "Message"
$tags = str_replace(' ',',',$subject); //DDIE
$uri =  str_replace(' ','-',$subject); //DDIE
$when = strtotime("now");   //date article was posted

?>
4

2 に答える 2

1

これを試して:

preg_match_all('/([^:\\s]+): (.+)/', $open_email_msg, $matches, PREG_SET_ORDER);

echo '<pre>' . print_r($matches, 1) . '</pre>';
于 2011-12-22T19:01:05.367 に答える
0

これを試して:

$lines = explode("\r\n", $open_email_msg); // Replace with whatever the line separator is
foreach($lines as $line){
    $temp = explode(": ", $line, 2);
    $msg[$temp[0]] = $temp[1];
}
// Now we have an array like
array(
    "Title" => "Article Title",
    "Tags" => "tag1 tag2",
    "Categories" => "Article Category, 2nd Article Category",
    "Snippet" => "Article Snippet",
    "Message" => "..."
)
于 2011-12-22T19:00:08.283 に答える