doutian3269 2015-09-03 16:40
浏览 24
已采纳

从PHP中删除HTML中的所有样式属性

I have to load the body of an HTML page without any style attribute and no link images and everything that is not 'plain text. I would like to do it in PHP and tried very solution but I have not solved. I load the html page with an ajax call to my script and then with a regular expression I take the body that then I want this cleared. Can you help me? This is the ajax call:

$.ajax({
       type: "GET"
       url: "core/proxy.php?url="+cerca,              
       success: function(data){
       var body = data.replace(/^[\S\s]*<body[^>]*?>/i, "")
       .replace(/<\/body[\S\s]*$/i, "");
        $("div#risultato").html(body);
    },
      error: function(){
      alert("failed");
    }
    });
});
  • 写回答

3条回答 默认 最新

  • dsgrs26202 2015-09-05 16:22
    关注

    Jose Antonio Riaza Valverde I corrected but nothing changes:

    $.ajax({
                //definisco il tipo della chiamata
                type: "GET",
                //url della risorsa da contattare
                url: "core/proxy.php?url="+cerca,
                //azione in caso di successo
                success: function(data)
                {
                    var body = data.replace(/^[\S\s]*<body[^>]*?>/i, "")
                    .replace(/<\/body[\S\s]*$/i, "");
                    $("div#risultato").html(body);
                    clearStyles(document.getElementById('risultato'));
    
                },
                //azione in caso di errore
                error: function()
                {
                    alert("Chiamata fallita");
                }
        });
    });
    

    and the function:

    function clearStyles(element) {
    element.setAttribute('style', ' ');
    element.setAttribute('img', ' ');
    element.setAttribute('a', ' ');
    for (var i = 0; i < element.children.length; i++) {
        clearStyles(element.children[i]);
    }
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看