fork download
  1. <?php
  2.  
  3. $text = 'text [date] text [date|Y-m-d] text [date|Y-m-d|today] text ...';
  4.  
  5. preg_match_all('/\[[^\[\]]+\]/', $text, $tags);
  6. foreach ($tags[0] as $tag) {
  7. print "$tag\n";
  8. preg_match_all('/(?<=^\[|\|)[^|\[\]]*(?=\||\]$)/', $tag, $dates);
  9. foreach ($dates[0] as $date) {
  10. print "$date\n";
  11. }
  12. }
Success #stdin #stdout 0.02s 24032KB
stdin
Standard input is empty
stdout
[date]
date
[date|Y-m-d]
date
Y-m-d
[date|Y-m-d|today]
date
Y-m-d
today