preg_match_basic.phpt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. --TEST--
  2. Test preg_match() function : basic functionality
  3. --FILE--
  4. <?php
  5. /* Function is implemented in ext/pcre/php_pcre.c */
  6. $string = 'Hello, world. [*], this is \ a string';
  7. var_dump(preg_match('/^[hH]ello,\s/', $string, $match1)); //finds "Hello, "
  8. var_dump($match1);
  9. var_dump(preg_match('/l^o,\s\w{5}/', $string, $match2, PREG_OFFSET_CAPTURE)); // tries to find "lo, world" at start of string
  10. var_dump($match2);
  11. var_dump(preg_match('/\[\*\],\s(.*)/', $string, $match3)); //finds "[*], this is \ a string";
  12. var_dump($match3);
  13. var_dump(preg_match('@\w{4}\s\w{2}\s\\\(?:\s.*)@', $string, $match4, PREG_OFFSET_CAPTURE, 14)); //finds "this is \ a string" (with non-capturing parentheses)
  14. var_dump($match4);
  15. var_dump(preg_match('/hello world/', $string, $match5)); //tries to find "hello world" (should be Hello, world)
  16. var_dump($match5);
  17. ?>
  18. --EXPECT--
  19. int(1)
  20. array(1) {
  21. [0]=>
  22. string(7) "Hello, "
  23. }
  24. int(0)
  25. array(0) {
  26. }
  27. int(1)
  28. array(2) {
  29. [0]=>
  30. string(23) "[*], this is \ a string"
  31. [1]=>
  32. string(18) "this is \ a string"
  33. }
  34. int(1)
  35. array(1) {
  36. [0]=>
  37. array(2) {
  38. [0]=>
  39. string(18) "this is \ a string"
  40. [1]=>
  41. int(19)
  42. }
  43. }
  44. int(0)
  45. array(0) {
  46. }