chop_variation4.phpt 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. --TEST--
  2. Test chop() function : usage variations - strings with embedded nulls
  3. --FILE--
  4. <?php
  5. /*
  6. * Testing chop() : with nulls embedded in input string
  7. */
  8. echo "*** Testing chop() : string with embedded nulls ***\n";
  9. // defining varous strings with embedded nulls
  10. $strings_with_nulls = array(
  11. "hello\0world",
  12. "\0hello",
  13. "hello\0",
  14. "\0\0hello\tworld\0\0",
  15. "\\0hello\\0",
  16. 'hello\0\0',
  17. chr(0),
  18. chr(0).chr(0),
  19. chr(0).'hello'.chr(0),
  20. 'hello'.chr(0).'world'
  21. );
  22. $count = 1;
  23. foreach($strings_with_nulls as $string) {
  24. echo "\n--- Iteration $count ---\n";
  25. var_dump( chop($string) );
  26. var_dump( chop($string, "\0") );
  27. var_dump( chop($string, '\0') );
  28. $count++;
  29. }
  30. echo "Done\n";
  31. ?>
  32. --EXPECTF--
  33. *** Testing chop() : string with embedded nulls ***
  34. --- Iteration 1 ---
  35. string(11) "hello%0world"
  36. string(11) "hello%0world"
  37. string(11) "hello%0world"
  38. --- Iteration 2 ---
  39. string(6) "%0hello"
  40. string(6) "%0hello"
  41. string(6) "%0hello"
  42. --- Iteration 3 ---
  43. string(5) "hello"
  44. string(5) "hello"
  45. string(6) "hello%0"
  46. --- Iteration 4 ---
  47. string(13) "%0%0hello world"
  48. string(13) "%0%0hello world"
  49. string(15) "%0%0hello world%0%0"
  50. --- Iteration 5 ---
  51. string(9) "\0hello\0"
  52. string(9) "\0hello\0"
  53. string(7) "\0hello"
  54. --- Iteration 6 ---
  55. string(9) "hello\0\0"
  56. string(9) "hello\0\0"
  57. string(5) "hello"
  58. --- Iteration 7 ---
  59. string(0) ""
  60. string(0) ""
  61. string(1) "%0"
  62. --- Iteration 8 ---
  63. string(0) ""
  64. string(0) ""
  65. string(2) "%0%0"
  66. --- Iteration 9 ---
  67. string(6) "%0hello"
  68. string(6) "%0hello"
  69. string(7) "%0hello%0"
  70. --- Iteration 10 ---
  71. string(11) "hello%0world"
  72. string(11) "hello%0world"
  73. string(11) "hello%0world"
  74. Done