fork download
  1. <?php
  2. $text = '
  3. *Heading 1* Text **SubHeading 1A** More Text **SubHeading 1B** Text**Subheading 1C**
  4. *Heading 2* Text **SubHeading 2A** More Text **SubHeading 2B** Even more text**Subheading 2C**
  5. ';
  6. $result = array();
  7. if (preg_match_all('/([*]+[^*]+[*]+)/', $text, $matches))
  8. $result = array_map(function ($v) {
  9. return str_replace('*', ' ', rtrim($v, '*'));
  10. }, $matches[1]);
  11.  
  12. print_r($result);
  13.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Array
(
    [0] =>   Heading 1
    [1] =>     SubHeading 1A
    [2] =>     SubHeading 1B
    [3] =>     Subheading 1C
    [4] =>   Heading 2
    [5] =>     SubHeading 2A
    [6] =>     SubHeading 2B
    [7] =>     Subheading 2C
)