fork download
  1. <?php
  2.  
  3. $strings = ["form.input|type()","form.input|type('text')","form.input|type('text', {'width': '100px', 'height': '50px'})", "form.input|type('image', {'path': '/path/to/image'})']"];
  4.  
  5. $regex = '~\(([^()]+)\)~';
  6.  
  7. foreach ($strings as $string) {
  8. if (preg_match($regex, $string, $match)) {
  9. list($key, $value) = explode(", ", $match[1], 1);
  10. echo $key, $value . "\n";
  11. }
  12. }
  13. ?>
Success #stdin #stdout #stderr 0.02s 24000KB
stdin
Standard input is empty
stdout
'text'
'text', {'width': '100px', 'height': '50px'}
'image', {'path': '/path/to/image'}
stderr
PHP Notice:  Undefined offset: 1 in /home/pLV4IW/prog.php on line 9
PHP Notice:  Undefined offset: 1 in /home/pLV4IW/prog.php on line 9
PHP Notice:  Undefined offset: 1 in /home/pLV4IW/prog.php on line 9