我問了這個問題:Javascript/jQuery find and delete array value in the rest of array,但我覺得我解釋錯了。這是我的第二次嘗試。jQuery查找並刪除使用相同數組的數組中的字符串
我使用PHP的imap函數拉電子郵件。我能夠成功地拉電子郵件。以下是代碼片段,展示瞭如何編碼。
foreach($all_email_dates as $email){
$email_id = explode(":", $email);
$email_id = $email_id[1];
$email = imap_fetchbody($inbox, $email_id, 1.1, FT_UID);
if($email == "") $email = imap_fetchbody($inbox, $email_id, 1, FT_UID);
if(imap_base64($email)) $email = imap_base64($email);
$email = quoted_printable_decode($email);
$email = preg_replace('/(^\w.+:\n)?(^>.*(\n|$))+/mi', '', $email);
array_push($emails, $email);
echo $email;
echo "<:>";
}
這將拉我需要的所有電子郵件,並按時間順序。
現在,我抓住他們使用AJAX調用,並嘗試在這裏操縱他們:
$.post('php/contacts-get-email.php', {email:email}, function(data) {
var email_body = data.split("<:>"); //Puts each email into an array
console.log(email_body);
//I have test code here for now that is not working
});
我想要做的是通過陣列(email_body
)迭代,找到並刪除任何重複的字符串。上面的輸出顯示在這裏:http://jsfiddle.net/exdjumqm/。 (我把它放在一個小提琴,而不是在這裏,因爲它會得到太長,在這裏顯示)--- 地址這裏有一個JSON文件有太多發揮:http://412webdesigns.com/uploads/emails.json
主要目標是刪除任何文本以前在電子郵件中。如果可能的話,我想保留回車格式的目的。
例如,第一封電子郵件有一段文字顯示在電子郵件2和4中。我希望刪除該文本。但我不確定該從哪裏出發。
如果您需要更多詳細信息,請讓我知道。謝謝
UPDATE 下面是粘貼在這裏的電子郵件字符串:
第一封電子郵件
Thanks so much name! We had a great time today too and can't wait to
see\r\nwhat the pictures look like! Looking forward to seeing them when you're
all\r\ndone editing! Thanks again :)\r\n
第二封電子郵件
Hi name!\r\n\r\n\r\n\r\nThank you for the email! You don't have to wait any
further!\r\n\r\n\r\n\r\nWe were able to get around 70 pictures that we think
were noteworthy! To \r\ndownload ALL of your pictures, head to
www.site.com\/download \r\nand use the password \"AN5k9W\". This should
automatically start your \r\ndownload, so check your downloads folder. It's a
half of a gig, so the file \r\nis pretty large!\r\n\r\n\r\n\r\nTo check out
some of the pics while you're waiting on the download, head to
\r\nhttp:\/\/site.com\/#\/151108-name_name-engagement or
\r\nfacebook.com\/site. Remember to like us and share your pics \r\nwith
anyone you want!\r\n\r\n\r\n\r\nLet us know what you think!\r\n\r\nWe look
forward to henameng from you!\r\n\r\nname & name\r\n\r\n\r\n\r\nOn Sun, Nov 8,
2015 at 2:52 PM name name <[email protected]> \r\nwrote:\r\n\r\n\r\nThanks so
much name! We had a great time today too and can't wait to see \r\nwhat the
pictures look like! Looking forward to seeing them when you're all \r\ndone
editing! Thanks again :)\r\n
你會發現第二個電子郵件包含第一因爲它是第一個回覆的電子郵件。
你想刪除先前已在一封電子郵件中的文本。 '文本',你的意思是,句子? (或文字?) – thewisenerd
也可以,你可以提供一個'.json'文件,可以使用? – thewisenerd
@VineethRaj句子,段落。如果你看一下上面的小提琴,你會看到第一封電子郵件是一段句子。在第二封電子郵件的底部,您會看到同一段再次重複。我希望將第一封電子郵件從第二封(和第四封)電子郵件中刪除。 – ntgCleaner