regex - PHP preg_match_all matches correctly but only gives one match -


i'm using regex pull out sections content submitted user:

preg_match_all("~\[section name=[\"|'](.*?)[\"|']\](.*?)\[\/section\]~", $content, $matches, preg_set_order); 

the purpose allow non-technical users create different named sections. far can tell, php's bbcode parser won't allow me pull out contents , attribute values array in way.

i'm not sure why accepted answer @ preg_match_all parsing, 1 match accepted, because suggests preg_match_all doesn't globally match default, , suggested g flag seems invalid.

the current function correctly matches that:

[section name="one"]this section one[/section] 

gets put $matches:

array (size=1)     0 =>          array (size=3)             0 => string '[section name="one"]this section one[/section]'             1 => string 'one'             2 => string 'this section one' 

this desired behavior.

however, doesn't add further matches $matches array, first.

what need have $matches populated matches in given string?

it strange, because when run script:

    $content = '[section name="one"]this section one[/section]<br />[section name="two"]this section two[/section]';     preg_match_all("~\[section name=[\"|'](.*?)[\"|']\](.*?)\[\/section\]~", $content, $matches, preg_set_order);     print_r($matches); 

it prints:

array ( [0] => array     (         [0] => [section name="one"]this section one[/section]         [1] => 1         [2] => section 1     )  [1] => array     (         [0] => [section name="two"]this section two[/section]         [1] => 2         [2] => section 2     )  ) 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -