fork download
  1. <?php
  2. $regex = '#\[element title=(.*)picture=(\d+)\](.*?)(\[caption\](.*)\[/caption\])?\[/element\]#i';
  3. $text = '[element title=element title picture=32]Lorem ipsum dolor[caption]Photo by John Doe[/caption][/element]';
  4.  
  5. preg_match ( $regex, $text, $match );
  6.  
  7. print_r( $match );
  8. ?>
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
Array
(
    [0] => [element title=element title picture=32]Lorem ipsum dolor[caption]Photo by John Doe[/caption][/element]
    [1] => element title 
    [2] => 32
    [3] => Lorem ipsum dolor
    [4] => [caption]Photo by John Doe[/caption]
    [5] => Photo by John Doe
)