regex - PHP extracting data from inbetween delimiters -


$heading = '';  $text = '         *heading 1* text **subheading 1a** more text **subheading 1b** text**subheading 1c**         *heading 2* text **subheading 2a** more text **subheading 2b** more text**subheading 2c**     ';      if(preg_match('#*(+?)#*',$text,$result));         $headings .= $result;      if(preg_match('#**(+?)#**',$text,$result));         $headings .= $result;      echo $heading; 

from $text, how possibly extract what's between * in between 1 * heading , whats between 2 ** subheading?

the output i'm trying achieve this:

heading 1     subheading 1a     subheading 1b     subheading 1c  heading 2     subheading 2a     subheading 2b     subheading 2c 

i did put great deal of effort, mind cannot think of anymore. can help?

try this:

$result = array(); if (preg_match_all('/([*]+[^*]+[*]+)/', $text, $matches))         $result = array_map(function ($v) {                 return str_replace('*', '  ', rtrim($v, '*'));         }, $matches[1]);  print_r($result); 

demo


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -