123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- --TEST--
- String functions
- --FILE--
- <?php
- echo "Testing strtok: ";
- $str = "testing 1/2\\3";
- $tok1 = strtok($str, " ");
- $tok2 = strtok("/");
- $tok3 = strtok("\\");
- $tok4 = strtok(".");
- if ($tok1 != "testing") {
- echo("failed 1\n");
- } elseif ($tok2 != "1") {
- echo("failed 2\n");
- } elseif ($tok3 != "2") {
- echo("failed 3\n");
- } elseif ($tok4 != "3") {
- echo("failed 4\n");
- } else {
- echo("passed\n");
- }
- echo "Testing strstr: ";
- $test = "This is a test";
- $found1 = strstr($test, chr(32));
- $found2 = strstr($test, "a ");
- if ($found1 != " is a test") {
- echo("failed 1\n");
- } elseif ($found2 != "a test") {
- echo("failed 2\n");
- } else {
- echo("passed\n");
- }
- echo "Testing strrchr: ";
- $test = "fola fola blakken";
- $found1 = strrchr($test, "b");
- $found2 = strrchr($test, chr(102));
- if ($found1 != "blakken") {
- echo("failed 1\n");
- } elseif ($found2 != "fola blakken") {
- echo("failed 2\n");
- }
- else {
- echo("passed\n");
- }
- echo "Testing strtoupper: ";
- $test = "abCdEfg";
- $upper = strtoupper($test);
- if ($upper == "ABCDEFG") {
- echo("passed\n");
- } else {
- echo("failed!\n");
- }
- echo "Testing strtolower: ";
- $test = "ABcDeFG";
- $lower = strtolower($test);
- if ($lower == "abcdefg") {
- echo("passed\n");
- } else {
- echo("failed!\n");
- }
- echo "Testing substr: ";
- $tests = $ok = 0;
- $string = "string12345";
- $tests++; if (substr($string, 2, 10) == "ring12345") { $ok++; }
- $tests++; if (substr($string, 4, 7) == "ng12345") { $ok++; }
- $tests++; if (substr($string, 4) == "ng12345") { $ok++; }
- $tests++; if (substr($string, 10, 2) == "5") { $ok++; }
- $tests++; if (substr($string, 6, 0) == "") { $ok++; }
- $tests++; if (substr($string, -2, 2) == "45") { $ok++; }
- $tests++; if (substr($string, 1, -1) == "tring1234") { $ok++; }
- $tests++; if (substr($string, -1, -2) == "") { $ok++; }
- $tests++; if (substr($string, -3, -2) == "3") { $ok++; }
- if ($tests == $ok) {
- echo("passed\n");
- } else {
- echo("failed!\n");
- }
- $raw = ' !"#$%&\'()*+,-./0123456789:;<=>?'
- . '@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'
- . '`abcdefghijklmnopqrstuvwxyz{|}~'
- . "\0";
- echo "Testing rawurlencode: ";
- $encoded = rawurlencode($raw);
- $correct = '%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F'
- . '%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_'
- . '%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~'
- . '%00';
- if ($encoded == $correct) {
- echo("passed\n");
- } else {
- echo("failed!\n");
- }
- echo "Testing rawurldecode: ";
- $decoded = rawurldecode($correct);
- if ($decoded == $raw) {
- echo("passed\n");
- } else {
- echo("failed!\n");
- }
- echo "Testing urlencode: ";
- $encoded = urlencode($raw);
- $correct = '+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F'
- . '%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_'
- . '%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E'
- . '%00';
- if ($encoded == $correct) {
- echo("passed\n");
- } else {
- echo("failed!\n");
- }
- echo "Testing urldecode: ";
- $decoded = urldecode($correct);
- if ($decoded == $raw) {
- echo("passed\n");
- } else {
- echo("failed!\n");
- }
- echo "Testing quotemeta: ";
- $raw = "a.\\+*?" . chr(91) . "^" . chr(93) . "b\$c";
- $quoted = quotemeta($raw);
- if ($quoted == "a\\.\\\\\\+\\*\\?\\[\\^\\]b\\\$c") {
- echo("passed\n");
- } else {
- echo("failed!\n");
- }
- echo "Testing ufirst: ";
- $str = "fahrvergnuegen";
- $uc = ucfirst($str);
- if ($uc == "Fahrvergnuegen") {
- echo("passed\n");
- } else {
- echo("failed!\n");
- }
- echo "Testing strtr: ";
- $str = "test abcdefgh";
- $tr = strtr($str, "def", "456");
- if ($tr == "t5st abc456gh") {
- echo("passed\n");
- } else {
- echo("failed!\n");
- }
- echo "Testing addslashes: ";
- $str = "\"\\'";
- $as = addslashes($str);
- if ($as == "\\\"\\\\\\'") {
- echo("passed\n");
- } else {
- echo("failed!\n");
- }
- echo "Testing stripslashes: ";
- $str = "\$\\'";
- $ss = stripslashes($str);
- if ($ss == "\$'") {
- echo("passed\n");
- } else {
- echo("failed!\n");
- }
- echo "Testing uniqid(true): ";
- $str = "prefix";
- $ui1 = uniqid($str, true);
- $ui2 = uniqid($str, true);
- $len = 29;
- if (strlen($ui1) == strlen($ui2) && strlen($ui1) == $len && $ui1 != $ui2) {
- echo("passed\n");
- } else {
- echo("failed!\n");
- }
- echo "Testing uniqid(false): ";
- $str = "prefix";
- $ui1 = uniqid($str);
- usleep( 1 );
- $ui2 = uniqid($str);
- $len = strncasecmp(PHP_OS, 'CYGWIN', 6) ? 19 : 29;
- if (strlen($ui1) == strlen($ui2) && strlen($ui1) == $len && $ui1 != $ui2) {
- echo("passed\n");
- } else {
- echo("failed!\n");
- }
- ?>
- --EXPECT--
- Testing strtok: passed
- Testing strstr: passed
- Testing strrchr: passed
- Testing strtoupper: passed
- Testing strtolower: passed
- Testing substr: passed
- Testing rawurlencode: passed
- Testing rawurldecode: passed
- Testing urlencode: passed
- Testing urldecode: passed
- Testing quotemeta: passed
- Testing ufirst: passed
- Testing strtr: passed
- Testing addslashes: passed
- Testing stripslashes: passed
- Testing uniqid(true): passed
- Testing uniqid(false): passed
|