Author Topic: Removing embedded images in mail script  (Read 618 times)

0 Members and 1 Guest are viewing this topic.

Offline brianlangeTopic starter

  • Enthusiast
  • Posts: 228
    • View Profile
Removing embedded images in mail script
« on: March 11, 2010, 03:25:33 PM »
I have an email popping script that needs to remove embedded images.
The images have "cid" in the source attribute like this one.
<img width="83" height="95" src=
"cid:image002.jpg@01CAC038.74744940" align="left" />

This is what I have so far which seems to work. Any way I can approve upon this? Thanks in advance.


$regEx = '/<img[\w\W]+src=[\r\n]?["\']cid[\w\W]+\s(\/>|>)/';

$img = '<img width="83" height="95" src=
"cid:image002.jpg@01CAC038.74744940" align="left" />';

$img = preg_replace($regEx, '', $img);
« Last Edit: March 11, 2010, 03:26:37 PM by brianlange »

Offline thebadbad

  • Addict
  • Posts: 1,610
  • Gender: Male
  • $me = str_replace($question, $answer, $post);
    • View Profile
Re: Removing embedded images in mail script
« Reply #1 on: March 11, 2010, 09:52:09 PM »
The way I would go about it:

$img preg_replace('~<img\b[^>]*\bsrc\s?=\s?([\'"])cid:[^\1]*\1[^>]*>~i'''$img);

Offline brianlangeTopic starter

  • Enthusiast
  • Posts: 228
    • View Profile
Re: Removing embedded images in mail script
« Reply #2 on: March 12, 2010, 11:55:33 AM »
Awesome, thank you very much.