fork download
  1. <?php
  2.  
  3. $strs = [
  4. '/' => true,
  5. '/?foo=bar' => true,
  6. '/?' => true,
  7. '/en' => true,
  8. '/ru' => true,
  9. '/ru/foo' => false
  10. ];
  11.  
  12. $expr = '/^\/(en|ru)?(\?.*)?$/';
  13.  
  14. $success = true;
  15. foreach ($strs as $str=>$expected) {
  16. $success = $success && $expected == preg_match($expr, $str);
  17. }
  18.  
  19. echo $success ?
  20. 'Tests passed!' : 'Tests failed!';
Success #stdin #stdout 0.02s 20568KB
stdin
Standard input is empty
stdout
Tests passed!