How do I remove

tag and its content from HTML using php

后端 未结 7 1207
既然无缘
既然无缘 2021-02-06 06:22

Below is the text I need to remove

tags from

Addiction, stress and subjective wellbeing

The need and signi

相关标签:
7条回答
  • 2021-02-06 06:52

    This code removes one p-tag:

    function parse($html) {
        $dom = new DOMDocument();
        @$dom->loadHTML($html);
        $ps = $dom->getElementsByTagName('p');
        //die('<pre>'.print_r($ps,1).'</pre>');
        if ($ps->length === 1){
            $p = $ps->item(0);
            return $p->nodeValue;
        } else {
            return '';
        }
    }
    
    0 讨论(0)
提交回复
热议问题