PHP simple html DOM remove all attributes from an html tag

跟風遠走 提交于 2019-12-05 14:37:11

When I use your code and example HTML, it does remove all the attributes from all the <p> tags, even the ones inside <font>, so I'm not sure why yours isn't working.

But it looks like simplehtmldom has methods that specifically deal with attributes so you don't have to use string functions:

$html = file_get_html('page.php');


foreach($html->find('p') as $p) {
    foreach ($p->getAllAttributes() as $attr => $val) {
        $p->removeAttribute($attr);
    }    
}
echo $html->innertext;

Hopefully that will be more effective.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!