Created
June 23, 2015 12:02
-
-
Save stefandoorn/f1e40d8867d48641a75b to your computer and use it in GitHub Desktop.
Mandrill PHP API filter embedded images array with embedded images used in e-mail HTML content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Insert list of embedded images (Mandrill API format) & HTML content | |
* Finds cid elements in HTML and filters $images list with it | |
* Unused images are shown as attachment in Outlook eg | |
* | |
* Format of $images: | |
* | |
* $images = array( | |
* array( | |
* 'type' => 'image/png', | |
* 'name' => 'name', | |
* 'content' => base64_encode(file_get_contents('/path/to/file')) | |
* ), | |
* .. | |
* ); | |
* | |
* @param array $images | |
* @param $html | |
* @return array | |
*/ | |
static public function stripImagesMandrillAPI(array $images, $html) | |
{ | |
if(!preg_match_all('/src="cid:(.*)"/Uims', $html, $matches)) { | |
return $images; | |
} | |
return array_filter($images, function($image) use ($matches) { | |
return in_array($image['name'], $matches[1]); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment