1--TEST-- 2Test strcspn() function : usage variations - different strings with default start and len args 3--FILE-- 4<?php 5/* Prototype : proto int strcspn(string str, string mask [, int start [, int len]]) 6 * Description: Finds length of initial segment consisting entirely of characters not found in mask. 7 If start or/and length is provided works like strcspn(substr($s,$start,$len),$bad_chars) 8 * Source code: ext/standard/string.c 9 * Alias to functions: none 10*/ 11 12/* 13* Testing strcspn() : with different strings as str argument and default start and len args 14*/ 15 16echo "*** Testing strcspn() : with different str and default start and len args ***\n"; 17 18// initialing required variables 19// defining different strings 20 21$strings = array( 22 "", 23 '', 24 "\n", 25 '\n', 26 "hello\tworld\nhello\nworld\n", 27 'hello\tworld\nhello\nworld\n', 28 "1234hello45world\t123", 29 '1234hello45world\t123', 30 "hello\0world\012", 31 'hello\0world\012', 32 chr(0).chr(0), 33 chr(0)."hello\0world".chr(0), 34 chr(0).'hello\0world'.chr(0), 35 "hello".chr(0)."world", 36 'hello'.chr(0).'world', 37 "hello\0\100\xaaaworld", 38 'hello\0\100\xaaaworld' 39 ); 40 41$mask = "sft\n34lw56r78d90\0\xaa\100o"; 42 43 44// loop through each element of the array for str argument 45 46foreach($strings as $str) { 47 echo "\n-- Iteration with str value \"$str\" --\n"; 48 49 //calling strcspn() with default arguments 50 var_dump( strcspn($str,$mask) ); 51}; 52 53echo "Done" 54?> 55--EXPECTF-- 56*** Testing strcspn() : with different str and default start and len args *** 57 58-- Iteration with str value "" -- 59int(0) 60 61-- Iteration with str value "" -- 62int(0) 63 64-- Iteration with str value " 65" -- 66int(0) 67 68-- Iteration with str value "\n" -- 69int(2) 70 71-- Iteration with str value "hello world 72hello 73world 74" -- 75int(2) 76 77-- Iteration with str value "hello\tworld\nhello\nworld\n" -- 78int(2) 79 80-- Iteration with str value "1234hello45world 123" -- 81int(2) 82 83-- Iteration with str value "1234hello45world\t123" -- 84int(2) 85 86-- Iteration with str value "hello%0world 87" -- 88int(2) 89 90-- Iteration with str value "hello\0world\012" -- 91int(2) 92 93-- Iteration with str value "%0%0" -- 94int(0) 95 96-- Iteration with str value "%0hello%0world%0" -- 97int(0) 98 99-- Iteration with str value "%0hello\0world%0" -- 100int(0) 101 102-- Iteration with str value "hello%0world" -- 103int(2) 104 105-- Iteration with str value "hello%0world" -- 106int(2) 107 108-- Iteration with str value "hello%0@�aworld" -- 109int(2) 110 111-- Iteration with str value "hello\0\100\xaaaworld" -- 112int(2) 113Done 114