getting all values from h1 tags using php

前端 未结 4 1203
灰色年华
灰色年华 2020-11-30 03:43

I want to receive an array that contains all the h1 tag values from a text

Example, if this where the given input string:

hello

4条回答
  •  情歌与酒
    2020-11-30 04:10

    function getTextBetweenTags($string, $tagname){
        $d = new DOMDocument();
        $d->loadHTML($string);
        $return = array();
        foreach($d->getElementsByTagName($tagname) as $item){
            $return[] = $item->textContent;
        }
        return $return;
    }
    

提交回复
热议问题