English 中文(简体)
将图像从html移除,如电子邮件在无图像可查的情况下将做
原标题:Remove images from html the same as gmail would do for emails without images enabled

我是PHP的一个简单的超文本电子邮件设计编辑,也显示了如何看待这一问题。

我认为,展示用户如何看待电子邮件客户,例如带有图像的电子邮件,也非常有益。

我的最好办法是什么? 任何人都知道如何通过电子邮件/传真等来做到这一点?

我是否简单删除了<代码>img-> src 和cs 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

我发现,这个问题具有相同的想法,尽管我实际上希望从超文本中删除成像和背后。

或者,,该代码也可修改,以便与背景图像一起工作?

最佳回答

我还建议使用PHP DOM,而不是常规,而后者往往不准确。 这里是你可以用来从你身上抹去所有信标和所有背景属性的范例:

// ...loading the DOM
$dom = new DOMDocument();
@$dom->loadHTML($string);  // Using @ to hide any parse warning sometimes resulting from markup errors
$dom->preserveWhiteSpace = false;
// Here we strip all the img tags in the document
$images = $dom->getElementsByTagName( img );
$imgs = array();
foreach($images as $img) {
    $imgs[] = $img;
}
foreach($imgs as $img) {
    $img->parentNode->removeChild($img);
}
// This part strips all  background  attribute in (all) the body tag(s)
$bodies = $dom->getElementsByTagName( body );
$bodybg = array();
foreach($bodies as $bg) {
    $bodybg[] = $bg;
}
foreach($bodybg as $bg) {
    $bg->removeAttribute( background );
}

$str = $dom->saveHTML();

I ve selected the body tags instead of the table, as the <table> itself doesn t have a background attribute, it only has bgcolor. 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

// Selecting all the elements since each one could have a style attribute
$alltags = $dom->getElementsByTagName( * );
$tags = array();
foreach($alltags as $tag) {
    $tags[] = $tag;
} $css = array();
foreach($tags as &$tag) {
    $oParser = new CSSParser("p{".$tag->getAttribute( style )."}");
    $oCss = $oParser->parse();
    foreach($oCss->getAllRuleSets() as $oRuleSet) {
        $oRuleSet->removeRule( background );
        $oRuleSet->removeRule( background-image );
    }
    $css = $oCss->__toString();
    $css = substr_replace($css,   , 0, 3);
    $css = substr_replace($css,   , -2, 2);
    if($css)
        $tag->setAttribute( style , $css);
}

举例说,如果你有的话

$string =  <!DOCTYPE html>
<html><body background="http://yo.ur/background/dot/com" etc="an attribute value">
<img src="http://your.pa/th/to/image"><img src="http://anoth.er/path/to/image">
<div style="background-image:url(http://inli.ne/css/background);border: 1px solid black">div content...</div>
<div style="background:url(http://inli.ne/css/background);border: 1px solid black">2nd div content...</div>
</body></html> ;

PHP将output

<!DOCTYPE html>
<html><body etc="an attribute value">
<div style="border: 1px solid black;">div content...</div>
<div style="border: 1px solid black;">2nd div content...</div>
</body></html>
问题回答

为了充分调和电子邮件或类似网络邮件的行为,将取代信标和背景:因此,信使显示持单人,向用户表明,这里有形象。

由于电文通常装在单体内。 我认为,你的最好猜测是清理电文服务器,拆除所有不想要的标签,并在预审时相应更换图像。

我将同意米哈勒的看法,即仅仅利用微粒验证你的超文本是不明智的,而且你也许应当把多功能树木推向安全。

为什么不提一下?

同前文所述一样:也许 Java/ j是答案。

这将研究贵审查区的所有图像,并将来源改变为股东的形象。 持股人也向持股人树立了背景形象。

页: 1 学历

$("#previewArea img").each(function(){
  $(this).attr("src","placeholder.jpg");
  $(this).addClass("hideBG");
});

CSS

.hideBG{
  background: url("placeholder.jpg");
}

不是测试的,而是工作——取决于您的设置和需求。

我认为,采用不处理“弧”特性的标签来扭转这一变化的最佳方式。

......将所有“img”改为“br”。

因此,用Ajax印刷过滤的超文本,用电弧特性检索所有新娘。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!