1--TEST-- 2Test strcspn() function : usage variations - with heredoc strings, varying mask & 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 heredoc string, varying mask and default start and len arguments 14*/ 15 16echo "*** Testing strcspn() : with different mask strings ***\n"; 17 18// initialing required variables 19// defining different heredoc strings 20$empty_heredoc = <<<EOT 21EOT; 22 23$heredoc_with_newline = <<<EOT 24\n 25 26EOT; 27 28$heredoc_with_characters = <<<EOT 29first line of heredoc string 30second line of heredoc string 31third line of heredocstring 32EOT; 33 34$heredoc_with_newline_and_tabs = <<<EOT 35hello\tworld\nhello\nworld\n 36EOT; 37 38$heredoc_with_alphanumerics = <<<EOT 39hello123world456 401234hello\t1234 41EOT; 42 43$heredoc_with_embedded_nulls = <<<EOT 44hello\0world\0hello 45\0hello\0 46EOT; 47 48$heredoc_with_hexa_octal = <<<EOT 49hello\0\100\xaaworld\0hello 50\0hello\0 51EOT; 52 53$heredoc_strings = array( 54 $empty_heredoc, 55 $heredoc_with_newline, 56 $heredoc_with_characters, 57 $heredoc_with_newline_and_tabs, 58 $heredoc_with_alphanumerics, 59 $heredoc_with_embedded_nulls, 60 $heredoc_with_hexa_octal 61 ); 62 63// defining array of mask strings 64$mask_array = array( 65 "", 66 '', 67 "\n\trsti \l", 68 '\n\trsti \l', 69 "\t", 70 "t\ ", 71 '\t', 72 "\t\ ", 73 " \t", 74 "\t\i\100\xaa" 75 ); 76 77 78// loop through each element of the arrays for string and mask arguments 79 80$count = 1; 81foreach($heredoc_strings as $str) { 82 echo "\n-- Iteration $count --\n"; 83 foreach($mask_array as $mask) { 84 var_dump( strcspn($str,$mask) ); // with default start and len value 85 } 86 $count++; 87} 88 89echo "Done" 90?> 91--EXPECTF-- 92*** Testing strcspn() : with different mask strings *** 93 94-- Iteration 1 -- 95int(0) 96int(0) 97int(0) 98int(0) 99int(0) 100int(0) 101int(0) 102int(0) 103int(0) 104int(0) 105 106-- Iteration 2 -- 107int(2) 108int(2) 109int(0) 110int(2) 111int(2) 112int(2) 113int(2) 114int(2) 115int(2) 116int(2) 117 118-- Iteration 3 -- 119int(86) 120int(86) 121int(1) 122int(1) 123int(86) 124int(4) 125int(4) 126int(5) 127int(5) 128int(1) 129 130-- Iteration 4 -- 131int(24) 132int(24) 133int(2) 134int(2) 135int(5) 136int(24) 137int(24) 138int(5) 139int(5) 140int(5) 141 142-- Iteration 5 -- 143int(31) 144int(31) 145int(2) 146int(2) 147int(26) 148int(31) 149int(31) 150int(26) 151int(26) 152int(26) 153 154-- Iteration 6 -- 155int(5) 156int(5) 157int(2) 158int(2) 159int(25) 160int(25) 161int(25) 162int(25) 163int(25) 164int(25) 165 166-- Iteration 7 -- 167int(5) 168int(5) 169int(2) 170int(2) 171int(27) 172int(27) 173int(27) 174int(27) 175int(27) 176int(6) 177Done 178