PHP Simple Html Dom get the plain text of div,but avoiding all other tags

前端 未结 4 391
庸人自扰
庸人自扰 2020-12-21 05:35

I use PHP Simple Html Dom to get some html,now i have a html dom like follow code,i need fetch the plain text inner div,but avoiding the p tags and their content(only retur

4条回答
  •  醉酒成梦
    2020-12-21 06:21

    It depends on what you mean by "avoiding the p tags".

    If you just want to remove the tags, then just running strip_tags() on it should work for what you want.

    If you actually want to just return "11111" (ie. strip the tags and their contents) then this isn't a viable solution. For that, something like this may work:

    $myDiv = $html->find('div'); // wherever your the div you're ending up with is
    $children = $myDiv->children; // get an array of children
    foreach ($children AS $child) {
        $child->outertext = ''; // This removes the element, but MAY NOT remove it from the original $myDiv
    }
    echo $myDiv->innertext;
    

提交回复
热议问题