File: strcspn_variation9.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (113 lines) | stat: -rw-r--r-- 2,640 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
--TEST--
Test strcspn() function : usage variations - different strings with default start and len args
--FILE--
<?php
/* Prototype  : proto int strcspn(string str, string mask [, int start [, int len]])
 * Description: Finds length of initial segment consisting entirely of characters not found in mask.
                If start or/and length is provided works like strcspn(substr($s,$start,$len),$bad_chars)
 * Source code: ext/standard/string.c
 * Alias to functions: none
*/

/*
* Testing strcspn() : with different strings as str argument and default start and len args
*/

echo "*** Testing strcspn() : with different str and default start and len args ***\n";

// initialing required variables
// defining different strings

$strings = array(
                   "",
           '',
           "\n",
           '\n',
           "hello\tworld\nhello\nworld\n",
           'hello\tworld\nhello\nworld\n',
           "1234hello45world\t123",
           '1234hello45world\t123',
           "hello\0world\012",
           'hello\0world\012',
           chr(0).chr(0),
           chr(0)."hello\0world".chr(0),
           chr(0).'hello\0world'.chr(0),
           "hello".chr(0)."world",
           'hello'.chr(0).'world',
           "hello\0\100\xaaaworld",
           'hello\0\100\xaaaworld'
                   );

$mask = "sft\n34lw56r78d90\0\xaa\100o";


// loop through each element of the array for str argument

foreach($strings as $str) {
      echo "\n-- Iteration with str value \"$str\" --\n";

      //calling strcspn() with default arguments
      var_dump( strcspn($str,$mask) );
};

echo "Done"
?>
--EXPECTF--
*** Testing strcspn() : with different str and default start and len args ***

-- Iteration with str value "" --
int(0)

-- Iteration with str value "" --
int(0)

-- Iteration with str value "
" --
int(0)

-- Iteration with str value "\n" --
int(2)

-- Iteration with str value "hello	world
hello
world
" --
int(2)

-- Iteration with str value "hello\tworld\nhello\nworld\n" --
int(2)

-- Iteration with str value "1234hello45world	123" --
int(2)

-- Iteration with str value "1234hello45world\t123" --
int(2)

-- Iteration with str value "hello%0world
" --
int(2)

-- Iteration with str value "hello\0world\012" --
int(2)

-- Iteration with str value "%0%0" --
int(0)

-- Iteration with str value "%0hello%0world%0" --
int(0)

-- Iteration with str value "%0hello\0world%0" --
int(0)

-- Iteration with str value "hello%0world" --
int(2)

-- Iteration with str value "hello%0world" --
int(2)

-- Iteration with str value "hello%0@aworld" --
int(2)

-- Iteration with str value "hello\0\100\xaaaworld" --
int(2)
Done