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

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

http://github.com/facebook/hiphop-php
PHP | 80 lines | 59 code | 9 blank | 12 comment | 1 complexity | 1d652caa5587d094e146106645a1fde3 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 single quoted strings to 'haystack' & 'needle' */
  7. echo "*** Testing strrchr() function: with various single 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. '#', //hexadecimal numeric string
  57. '\101', //octal numeric string
  58. 'A',
  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. ?>