PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/test/zend/bad/ext/standard/tests/strings/strrchr_variation1.php

http://github.com/facebook/hiphop-php
PHP | 80 lines | 59 code | 9 blank | 12 comment | 1 complexity | 140a5fadcd9761fcb40f832f05ce311e 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. /* Prototype : string strrchr(string $haystack, string $needle);
  3. * Description: Finds the last occurrence of a character in a string.
  4. * Source code: ext/standard/string.c
  5. */
  6. /* Test strrchr() function by passing various double quoted strings for 'haystack' & 'needle' */
  7. echo "*** Testing strrchr() function: with various double quoted strings ***";
  8. $haystack = "Hello,\t\n\0\n $&!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 ";
  9. $needle = array(
  10. //regular strings
  11. "l",
  12. "L",
  13. "HELLO",
  14. "hEllo",
  15. //escape characters
  16. "\t",
  17. "\T",
  18. " ",
  19. "\n",
  20. "\N",
  21. "
  22. ", //new line
  23. //nulls
  24. "\0",
  25. NULL,
  26. null,
  27. //boolean false
  28. FALSE,
  29. false,
  30. //empty string
  31. "",
  32. //special chars
  33. " ",
  34. "$",
  35. " $",
  36. "&",
  37. "!#",
  38. "%\o",
  39. "\o,",
  40. "()",
  41. "*+",
  42. "+",
  43. "-",
  44. ".",
  45. ".;",
  46. ":;",
  47. ";",
  48. "<=>",
  49. ">",
  50. "=>",
  51. "?",
  52. "@",
  53. "@hEllo",
  54. "12345", //decimal numeric string
  55. "\x23", //hexadecimal numeric string
  56. "#", //respective ASCII char of \x23
  57. "\101", //octal numeric string
  58. "A", //respective ASCII char of \101
  59. "456HEE", //numerics + chars
  60. 42, //needle as int(ASCII value of "*")
  61. $haystack //haystack as needle
  62. );
  63. /* loop through to get the position of the needle in haystack string */
  64. $count = 1;
  65. for($index=0; $index<count($needle); $index++) {
  66. echo "\n-- Iteration $count --\n";
  67. var_dump( strrchr($haystack, $needle[$index]) );
  68. $count++;
  69. }
  70. echo "*** Done ***";
  71. ?>