Annotation of embedaddon/php/ext/pcre/tests/pcre_count.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: preg_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;
! 9: var_dump(preg_replace($regex, 'xxxx', $string, -1, $count));
! 10: var_dump($count);
! 11: //////////////////////////////////////////////////////
! 12:
! 13: $regex = '/([a-z]+)/';
! 14:
! 15: $string= 'Here must only number like 42 and 13 appear';
! 16: var_dump(preg_replace($regex, 'xxxx', $string, -1, $count));
! 17: var_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/|/';
! 23: var_dump(preg_replace($regex, '...', $string, -1, $count));
! 24: var_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/|/';
! 29: var_dump(preg_replace($regex, '...', $string, -1));
! 30: var_dump($count);
! 31: ?>
! 32: --EXPECT--
! 33: string(56) "xxxx xxxx 1-a-3-4 1-2-a-4 1-2-3-a a-a-a-a xxxx xxxx-xxxx"
! 34: int(5)
! 35: string(41) "Hxxxx xxxx xxxx xxxx xxxx 42 xxxx 13 xxxx"
! 36: int(7)
! 37: string(25) "... ... ... ... v1c0d1/|/"
! 38: int(4)
! 39: string(25) "... ... ... ... v1c0d1/|/"
! 40: NULL
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>