php - Get html between comments block Simple HTM DOM -


how can take block of dom identify 'comment' tag, like

<!-- start block --> <p>hello world etc</p> <div>something</div> <!-- end of block --> 

i'm using simple php dom parser, doc incomplete, http://simplehtmldom.sourceforge.net/manual.htm. it's fine if can pure php.

you can try iterate thru elements first, if found starting comment, skip first, add flag starts concatenation of next elements. if reach end-point, stop concatenation:

$html_string = '<!-- start block --> <p>hello world etc</p> <div>something</div> <div>something2</div> <!-- end of block --> <div>something3</div> ';  $html = str_get_html($html_string); // start point $start = $html->find('*'); $output = ''; $go = false; foreach($start $e) {      if($e->innertext === '<!-- start block -->') {         $go = true;         continue;     } elseif($e->innertext === '<!-- end of block -->') {         break;     }      if($go) {         $output .= $e;     }    }  echo $output; 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -