/hphp/test/zend/bad/ext/standard/tests/strings/strrchr_variation2.php
PHP | 80 lines | 59 code | 9 blank | 12 comment | 1 complexity | 1d652caa5587d094e146106645a1fde3 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
- <?php
- /* Prototype : string strrchr(string $haystack, string $needle);
- * Description: Finds the last occurrence of a character in a string.
- * Source code: ext/standard/string.c
- */
- /* Test strrchr() function by passing various single quoted strings to 'haystack' & 'needle' */
- echo "*** Testing strrchr() function: with various single quoted strings ***";
- $haystack = 'Hello,\t\n\0\n $&!#%\o,()*+-./:;<=>?@hello123456he \x234 \101 ';
- $needle = array(
- //regular strings
- 'l',
- 'L',
- 'HELLO',
- 'hEllo',
- //escape characters
- '\t',
- '\T',
- ' ',
- '\n',
- '\N',
- '
- ', //new line
- //nulls
- '\0',
- NULL,
- null,
- //boolean false
- FALSE,
- false,
- //empty string
- '',
- //special chars
- ' ',
- '$',
- ' $',
- '&',
- '!#',
- '%\o',
- '\o,',
- '()',
- '*+',
- '+',
- '-',
- '.',
- '.;',
- ':;',
- ';',
- '<=>',
- '>',
- '=>',
- '?',
- '@',
- '@hEllo',
- '12345', //decimal numeric string
- '\x23', //hexadecimal numeric string
- '#', //hexadecimal numeric string
- '\101', //octal numeric string
- 'A',
- '456HEE', //numerics + chars
- 42, //needle as int(ASCII value of '*')
- $haystack //haystack as needle
- );
-
- /* loop through to get the position of the needle in haystack string */
- $count = 1;
- for($index=0; $index<count($needle); $index++) {
- echo "\n-- Iteration $count --\n";
- var_dump( strrchr($haystack, $needle[$index]) );
- $count ++;
- }
- echo "*** Done ***";
- ?>