PageRenderTime 37ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/slow/ext_preg/ext_preg_e.php

http://github.com/facebook/hiphop-php
PHP | 57 lines | 48 code | 9 blank | 0 comment | 0 complexity | fe97c939cf89a7a4824783f5b46fce3d MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. function test_preg_rep($a,$b,$c) {
  3. return strtoupper($c).$a;
  4. }
  5. function test_preg_replace() {
  6. var_dump(preg_replace(
  7. "/no match/e",
  8. "strtoupper(\"$1\")",
  9. "doesn't match"
  10. ));
  11. var_dump(preg_replace(
  12. "/no match/e",
  13. "bad_func(\"$1\")",
  14. "doesn't match"
  15. ));
  16. var_dump(preg_replace(
  17. "/(<\\/?\\w+[^>]*>)/e",
  18. "strtoupper(\"$1\")",
  19. "<html><body></body></html>"
  20. ));
  21. var_dump(preg_replace(
  22. "/#([A-Fa-f0-9]{3,6});/e",
  23. "strtolower(\"#\\1;\");",
  24. "#AAAA;"
  25. ));
  26. var_dump(preg_replace(
  27. "/rgb\\(([0-9]{1,3}), ([0-9]{1,3}), ([0-9]{1,3})\\)/e",
  28. "sprintf(\"%02x%02x%02x\", \"\\1\", \"\\2\", \"\\3\")",
  29. "rgb(13, 14, 15)"
  30. ));
  31. var_dump(preg_replace(
  32. "/(a*)(b*)/e",
  33. "test_preg_rep(\"\\1\",\"smu\\\"rf\",\"\\2\")",
  34. "aaabbbblahblahaabbbababab"
  35. ));
  36. var_dump(preg_replace_callback(
  37. "/a/e",
  38. "test_preg_rep",
  39. "a"
  40. ));
  41. var_dump(preg_replace(
  42. "/(a)/e",
  43. "str_repeat('$1', 500)",
  44. "aaaaaaaaaaaaaaaaaaaa"
  45. ));
  46. }
  47. test_preg_replace();