fork download
  1. <?php
  2.  
  3. function parse_tag($tag) {
  4. preg_match('#\[(.*?)\]#', $tag, $matches);
  5. return explode(':', $matches[1]);
  6. }
  7.  
  8. $tests = array(
  9. '[NAME]' => array('NAME'),
  10. '[PRODUCT:SHIRT]' => array('PRODUCT', 'SHIRT'),
  11. '[ARTICLE:23]' => array('ARTICLE', 23)
  12. );
  13.  
  14. foreach($tests as $search => $expected) {
  15. $result = parse_tag($search);
  16. assert($expected == $result);
  17. }
  18.  
  19. ?>
Success #stdin #stdout 0.02s 13064KB
stdin
Standard input is empty
stdout
Standard output is empty