php - preg_match_all does not match data in string -


i'm trying pull out text on lines begins *, ** , *** alone, , not other text that's under or above it. text on lines beginning *,**,***.

that data comes textarea in form , looks this:

*heading 1* user text **subheading 1a** more usertext ***subsubheading 1aa*** more usertext **subheading 1b** more usertext **subheading 1c** more usertext **subheading 1d** more usertext *heading 2* more usertext **subheading 2a** more usertext **subheading 2b** more usertext **subheading 2c** more usertext ***subheading 2c** more usertext 

the end result end results this, , not of user text.

heading 1 subheading 1a subsubheading 1aa subheading 1b subheading 1c subheading 1d heading 2 subheading 2a subheading 2b subheading 2c subheading 2d 

i modified previous answer match lines beginning *, ** , ***, don't seem getting results, blank array.

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

how results want? cant figure i'm failing.

you can se regex:

$s = <<< eof *heading 1* user text **subheading 1a** more usertext ***subsubheading 1aa*** more usertext **subheading 1b** more usertext **subheading 1c** more usertext **subheading 1d** more usertext *heading 2* more usertext **subheading 2a** more usertext **subheading 2b** more usertext **subheading 2c** more usertext ***subheading 2d** more usertext eof; if ( preg_match_all('~^\*{1,3}(.+?)\*{1,3}$~m', $s, $m) )    print_r($m[1]); 

output:

array (     [0] => heading 1     [1] => subheading 1a     [2] => subsubheading 1aa     [3] => subheading 1b     [4] => subheading 1c     [5] => subheading 1d     [6] => heading 2     [7] => subheading 2a     [8] => subheading 2b     [9] => subheading 2c     [10] => subheading 2d ) 

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 -