1--TEST--
2Test strcspn() function : usage variations - with heredoc 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 heredoc strings as str argument
14*/
15
16echo "*** Testing strcspn() : 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 = "fth12\ne67890\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( strcspn($str,$mask) ); // with default start and len values
71};
72
73echo "Done"
74?>
75--EXPECT--
76*** Testing strcspn() : with heredoc strings ***
77
78-- Iteration with str value as "" --
79int(0)
80
81-- Iteration with str value as "
82
83" --
84int(0)
85
86-- Iteration with str value as "first line of heredoc string
87second line of heredoc string
88third line of heredocstring" --
89int(0)
90
91-- Iteration with str value as "hello	world
92hello
93world
94" --
95int(0)
96
97-- Iteration with str value as "hello123world456
981234hello	1234" --
99int(0)
100
101-- Iteration with str value as "hello�world�hello
102�hello�" --
103int(0)
104
105-- Iteration with str value as "hello�@�world�hello
106�hello�" --
107int(0)
108Done
109