PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/test/zend/good/ext/standard/tests/strings/strrchr_variation12.php

http://github.com/facebook/hiphop-php
PHP | 27 lines | 18 code | 2 blank | 7 comment | 1 complexity | 82c55dee92f2739d22783e0561214190 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. <?hh
  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: with binary values & null terminated strings passed to 'str1' & 'str2' */
  7. <<__EntryPoint>> function main(): void {
  8. echo "*** Test strrchr() function: binary safe ***\n";
  9. $haystacks = varray[
  10. "Hello".chr(0)."World",
  11. chr(0)."Hello World",
  12. "Hello World".chr(0),
  13. chr(0).chr(0).chr(0),
  14. "Hello\0world",
  15. "\0Hello",
  16. "Hello\0"
  17. ];
  18. for($index = 0; $index < count($haystacks); $index++ ) {
  19. //needle as null string
  20. var_dump( strrchr($haystacks[$index], "\0") );
  21. //needle as NULL
  22. var_dump( strrchr($haystacks[$index], NULL) );
  23. }
  24. echo "*** Done ***";
  25. }