1--TEST-- 2Test strspn() function : usage variations - with heredoc 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 heredoc strings as str argument 14*/ 15 16echo "*** Testing strspn() : with heredoc 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$mask = "sfth12\ne34l567890\0\xaa\100o"; 64 65 66// loop through each element of the array for str argument 67 68foreach($heredoc_strings as $str) { 69 echo "\n-- Iteration with str value as \"$str\" --\n"; 70 var_dump( strspn($str,$mask) ); // with default start and len values 71}; 72 73echo "Done" 74?> 75--EXPECTF-- 76*** Testing strspn() : with heredoc strings *** 77 78-- Iteration with str value as "" -- 79int(0) 80 81-- Iteration with str value as " 82 83" -- 84int(2) 85 86-- Iteration with str value as "first line of heredoc string 87second line of heredoc string 88third line of heredocstring" -- 89int(1) 90 91-- Iteration with str value as "hello world 92hello 93world 94" -- 95int(5) 96 97-- Iteration with str value as "hello123world456 981234hello 1234" -- 99int(8) 100 101-- Iteration with str value as "hello%0world%0hello 102%0hello%0" -- 103int(6) 104 105-- Iteration with str value as "hello%0@�world%0hello 106%0hello%0" -- 107int(8) 108Done 109