1--TEST-- 2Test strspn() function : usage variations - different strings with default start and len args 3--FILE-- 4<?php 5/* Prototype : proto int strspn(string str, string mask [, int start [, int len]]) 6 * Description: Finds length of initial segment consisting entirely of characters found in mask. 7 If start or/and length is provided works like strspn(substr($s,$start,$len),$good_chars) 8 * Source code: ext/standard/string.c 9 * Alias to functions: none 10*/ 11 12/* 13* Testing strspn() : with different strings as str argument and default start and len args 14*/ 15 16echo "*** Testing strspn() : 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 = "sfth12\ne34lw56r78d90\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 strspn() with default arguments 50 var_dump( strspn($str,$mask) ); 51}; 52 53echo "Done" 54?> 55--EXPECTF-- 56*** Testing strspn() : 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(1) 67 68-- Iteration with str value "\n" -- 69int(0) 70 71-- Iteration with str value "hello world 72hello 73world 74" -- 75int(5) 76 77-- Iteration with str value "hello\tworld\nhello\nworld\n" -- 78int(5) 79 80-- Iteration with str value "1234hello45world 123" -- 81int(16) 82 83-- Iteration with str value "1234hello45world\t123" -- 84int(16) 85 86-- Iteration with str value "helloworld 87" -- 88int(12) 89 90-- Iteration with str value "hello\0world\012" -- 91int(5) 92 93-- Iteration with str value "" -- 94int(2) 95 96-- Iteration with str value "helloworld" -- 97int(13) 98 99-- Iteration with str value "hello\0world" -- 100int(6) 101 102-- Iteration with str value "helloworld" -- 103int(11) 104 105-- Iteration with str value "helloworld" -- 106int(11) 107 108-- Iteration with str value "hello@�aworld" -- 109int(8) 110 111-- Iteration with str value "hello\0\100\xaaaworld" -- 112int(5) 113Done 114