php explode select multi choose -


i want divide these html serval several part. 1 <h2> or <h3> <p> , <span> 1 part. tried explode array('<h2>','<h3>'), caused warning. explode not support multi choose.

so how perfectly? thanks.

$text=<<<eot <h2>title1</h2> <p>something</p> <span>something</span> <h3>title2</h3> <p>something</p> <p>something</p> <p>something</p> <h2>title3</h2> <span>something</span> <h2>title4</h2> <span>something</span> <p>something</p> <p>something</p> eot;  foreach ($text $result) {      $arr = explode(array('<h2>','<h3>'),$result);     reset($arr);      foreach($arr $line){         echo $line.'<hr />';     }  } 

warning: invalid argument supplied foreach() on line 23;

my expected output is:

<h2>title1</h2> <p>something</p> <span>something</span> ___________________________ <h3>title2</h3> <p>something</p> <p>something</p> <p>something</p> ___________________________ <h2>title3</h2> <span>something</span> ___________________________ <h2>title4</h2> <span>something</span> <p>something</p> <p>something</p> ___________________________ 

you can use preg_split() explode @ different things. can use regex here:

$text = <<<eot <h2>title1</h2> <p>something</p> ... eot;  $arr = preg_split("#(?=<h[23]>)#", $text);  if(isset($arr[0]) && trim($arr[0])=='') array_shift($arr); // remove first block if empty  foreach($arr $block){     echo $block."<hr />\n"; } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -