xref: /PHP-8.2/ext/pcre/tests/pcre_count.phpt (revision c4490025)
1--TEST--
2preg_replace() fifth parameter - count
3--FILE--
4<?php
5$regex = '/(([0-9a-z]+)-([0-9]+))-(([0-9]+)-([0-9]+))/';
6
7$string= '1-2-3-4 a-2-3-4 1-a-3-4 1-2-a-4 1-2-3-a a-a-a-a 4-3-2-1 100-200-300-400-500-600-700-800';
8$count = 0;
9var_dump(preg_replace($regex, 'xxxx', $string, -1, $count));
10var_dump($count);
11//////////////////////////////////////////////////////
12
13$regex = '/([a-z]+)/';
14
15$string= 'Here must only number like 42 and 13 appear';
16var_dump(preg_replace($regex, 'xxxx', $string, -1, $count));
17var_dump($count);
18
19////////////////////////////////////////////////////////
20$regex = '~((V(I|1)(4|A)GR(4|A))|(V(I|1)C(0|O)D(I|1)(N|\/\\\/)))~i';
21
22$string= 'Viagra V14GR4 Vicodin V1C0D1/\/ v1c0d1/|/';
23var_dump(preg_replace($regex, '...', $string, -1, $count));
24var_dump($count);
25////////////////////////////////////////////////////////
26$regex = '~((V(I|1)(4|A)GR(4|A))|(V(I|1)C(0|O)D(I|1)(N|\/\\\/)))~i';
27$count = NULL;
28$string= 'Viagra V14GR4 Vicodin V1C0D1/\/ v1c0d1/|/';
29var_dump(preg_replace($regex, '...', $string, -1));
30var_dump($count);
31?>
32--EXPECT--
33string(56) "xxxx xxxx 1-a-3-4 1-2-a-4 1-2-3-a a-a-a-a xxxx xxxx-xxxx"
34int(5)
35string(41) "Hxxxx xxxx xxxx xxxx xxxx 42 xxxx 13 xxxx"
36int(7)
37string(25) "... ... ... ... v1c0d1/|/"
38int(4)
39string(25) "... ... ... ... v1c0d1/|/"
40NULL
41