2007-09-14 19:14:52 +00:00
|
|
|
|
--TEST--
|
|
|
|
|
Test chop() function : usage variations - strings with embedded nulls
|
|
|
|
|
--FILE--
|
|
|
|
|
<?php
|
|
|
|
|
/* Prototype : string chop ( string $str [, string $charlist] )
|
|
|
|
|
* Description: Strip whitespace (or other characters) from the end of a string
|
|
|
|
|
* Source code: ext/standard/string.c
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Testing chop() : with nulls embedded in input string
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
echo "*** Testing chop() : string with embedded nulls ***\n";
|
|
|
|
|
|
|
|
|
|
// defining varous strings with embedded nulls
|
|
|
|
|
$strings_with_nulls = array(
|
|
|
|
|
"hello\0world",
|
|
|
|
|
"\0hello",
|
|
|
|
|
"hello\0",
|
|
|
|
|
"\0\0hello\tworld\0\0",
|
|
|
|
|
"\\0hello\\0",
|
|
|
|
|
'hello\0\0',
|
|
|
|
|
chr(0),
|
|
|
|
|
chr(0).chr(0),
|
|
|
|
|
chr(0).'hello'.chr(0),
|
|
|
|
|
'hello'.chr(0).'world'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$count = 1;
|
|
|
|
|
foreach($strings_with_nulls as $string) {
|
|
|
|
|
echo "\n--- Iteration $count ---\n";
|
|
|
|
|
var_dump( chop($string) );
|
|
|
|
|
var_dump( chop($string, "\0") );
|
|
|
|
|
var_dump( chop($string, '\0') );
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo "Done\n";
|
|
|
|
|
?>
|
2008-05-27 10:50:48 +00:00
|
|
|
|
--EXPECT--
|
2007-09-14 19:14:52 +00:00
|
|
|
|
*** Testing chop() : string with embedded nulls ***
|
|
|
|
|
|
|
|
|
|
--- Iteration 1 ---
|
|
|
|
|
unicode(11) "hello |