2 /* Prototype : proto int strspn(string str, string mask [, int start [, int len]])
3 * Description: Finds length of initial segment consisting entirely of characters found in mask.
4 If start or/and length is provided works like strspn(substr($s,$start,$len),$good_chars)
5 * Source code: ext/standard/string.c
6 * Alias to functions: none
10 * Testing strspn() : with heredoc string, varying start and default len arguments
13 echo "*** Testing strspn() : with different start values ***\n";
15 // initialing required variables
16 // defining different heredoc strings
17 $empty_heredoc = <<<EOT
20 $heredoc_with_newline = <<<EOT
25 $heredoc_with_characters = <<<EOT
26 first line of heredoc string
27 second line of heredoc string
28 third line of heredocstring
31 $heredoc_with_newline_and_tabs = <<<EOT
32 hello\tworld\nhello\nworld\n
35 $heredoc_with_alphanumerics = <<<EOT
40 $heredoc_with_embedded_nulls = <<<EOT
45 $heredoc_with_hexa_octal = <<<EOT
46 hello\0\100\xaaworld\0hello
50 // defining array of different heredoc strings
51 $heredoc_strings = array(
53 $heredoc_with_newline,
54 $heredoc_with_characters,
55 $heredoc_with_newline_and_tabs,
56 $heredoc_with_alphanumerics,
57 $heredoc_with_embedded_nulls,
58 $heredoc_with_hexa_octal
61 // defining array of different mask strings
75 // defining array of different start values
82 2147483647, // max positive integer
83 -2147483648, // min negative integer
87 // loop through each element of the array for heredoc strings, mask strings and start values
91 foreach($heredoc_strings as $str) {
92 echo "\n-- Iteration $count --\n";
93 foreach($mask_array as $mask) {
94 foreach($start_array as $start) {
95 var_dump( strspn($str,$mask,$start) ); // with default len value