Find multiple patterns with a single preg_match_all in PHP

后端 未结 4 474
独厮守ぢ
独厮守ぢ 2021-01-01 04:49

Using PHP and preg_match_all I\'m trying to get all the HTML content between the following tags (and the tags also):

paragraph text

don\'t
4条回答
  •  醉话见心
    2021-01-01 05:14

    If you are to use a DOM parser, and you should, here's how. A contributor posted a useful function for obtaining a DOMNode's innerHTML, which I will use in the following example:

    $dom = new DOMDocument;
    $dom->loadHTML($html);
    
    $p = $dom->getElementsByTagName('p')->item(0); // first 

    node $ul = $dom->getElementsByTagName('ul')->item(0); // first

      node $table = $dom->getElementsByTagName('table')->item(0); // first node echo DOMinnerHTML($p); echo DOMinnerHTML($ul); echo DOMinnerHTML($table);

      提交回复
      热议问题