I am writing a simple HTML email design editor in PHP and also show a demo of how this will look.
I think it would also be very useful to show the user how this will look in an email client such as gmail with images turned off.
What is my best approach for this? Anybody know how this is done in gmail/hotmail etc?
Do I simple remove img -> src and css background: url with a reg expression?
I would like to remove the background parts from:
background="url" used in tables and
background-image:url(url); used inline css
I found this question which has the same kind of idea, although I would like to actually remove the img and backrgound-images from the HTML text.
Or could this code be modified to work with background images also?
I would also suggest using PHP DOM instead of regex, which are often inaccurate. Here is an example code you could use to strip all the img tags and all the background attributes from your string:
I’ve selected the body tags instead of the table, as the
<table>itself doesn’t have abackgroundattribute, it only hasbgcolor.To strip the background inline css property, you can use the sabberworm’s PHP CSS Parser
to parse the CSS retrieved from the DOM: try this
Using all this code togheter, for example if you have a
The PHP will output