preg_quote_basic.phpt 999 B

1234567891011121314151617181920212223
  1. --TEST--
  2. Test preg_quote() function : basic functionality
  3. --FILE--
  4. <?php
  5. /*
  6. * Function is implemented in ext/pcre/php_pcre.c
  7. */
  8. $string_before = '/this *-has \ metacharacters^ in $';
  9. print "\$string_before looks like: $string_before\n"; //$string_before is printed as is written
  10. $string_after = preg_quote($string_before, '/');
  11. print "\$string_after looks like: $string_after, with metacharacters and / (set as delimiter) escaped\n"; //$string_after is printed with metacharacters escaped.
  12. $string1 = 'testing - /this *-has \ metacharacters^ in $ should work';
  13. var_dump(preg_match('/^[tT]\w{6} - ' . preg_quote($string_before, '/') . ' [a-z]*\s*work$/', $string1, $matches1));
  14. var_dump($matches1);
  15. ?>
  16. --EXPECT--
  17. $string_before looks like: /this *-has \ metacharacters^ in $
  18. $string_after looks like: \/this \*\-has \\ metacharacters\^ in \$, with metacharacters and / (set as delimiter) escaped
  19. int(1)
  20. array(1) {
  21. [0]=>
  22. string(58) "testing - /this *-has \ metacharacters^ in $ should work"
  23. }