How to extract html comments and all html contained by node?

前端 未结 4 606
猫巷女王i
猫巷女王i 2020-12-01 22:57

I\'m creating a little web app to help me manage and analyze the content of my websites, and cURL is my favorite new toy. I\'ve figured out how to extract info about all so

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 23:25

    For the HTML comments a fast method is:

     function getComments ($html) {
    
         $rcomments = array();
         $comments = array();
    
         if (preg_match_all('#<\!--(.*?)-->#is', $html, $rcomments)) {
    
             foreach ($rcomments as $c) {
                 $comments[] = $c[1];
             }
    
             return $comments;
    
         } else {
             // No comments matchs
             return null;
         }
    
     }
    

提交回复
热议问题