getting all values from h1 tags using php

前端 未结 4 1208
灰色年华
灰色年华 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

    Alternative to DOM. Use when memory is an issue.

    $html = <<< HTML
    
    

    helloworld

    random text

    title number two!

    HTML; $reader = new XMLReader; $reader->xml($html); while($reader->read() !== FALSE) { if($reader->name === 'h1' && $reader->nodeType === XMLReader::ELEMENT) { echo $reader->readString(); } }

提交回复
热议问题