1 | <?php
|
---|
2 | // +----------------------------------------------------------------------+
|
---|
3 | // | PHP Version 4 |
|
---|
4 | // +----------------------------------------------------------------------+
|
---|
5 | // | Copyright (c) 1997-2004 The PHP Group |
|
---|
6 | // +----------------------------------------------------------------------+
|
---|
7 | // | This source file is subject to version 3.0 of the PHP license, |
|
---|
8 | // | that is bundled with this package in the file LICENSE, and is |
|
---|
9 | // | available at through the world-wide-web at |
|
---|
10 | // | http://www.php.net/license/3_0.txt. |
|
---|
11 | // | If you did not receive a copy of the PHP license and are unable to |
|
---|
12 | // | obtain it through the world-wide-web, please send a note to |
|
---|
13 | // | license@php.net so we can mail you a copy immediately. |
|
---|
14 | // +----------------------------------------------------------------------+
|
---|
15 | // | Authors: Aidan Lister <aidan@php.net> |
|
---|
16 | // | Stephan Schmidt <schst@php.net> |
|
---|
17 | // +----------------------------------------------------------------------+
|
---|
18 | //
|
---|
19 | // $Id: strripos.php,v 1.24 2005/08/10 10:19:59 aidan Exp $
|
---|
20 |
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Replace strripos()
|
---|
24 | *
|
---|
25 | * @category PHP
|
---|
26 | * @package PHP_Compat
|
---|
27 | * @link http://php.net/function.strripos
|
---|
28 | * @author Aidan Lister <aidan@php.net>
|
---|
29 | * @version $Revision: 1.24 $
|
---|
30 | * @since PHP 5
|
---|
31 | * @require PHP 4.0.0 (user_error)
|
---|
32 | */
|
---|
33 | if (!function_exists('strripos')) {
|
---|
34 | function strripos($haystack, $needle, $offset = null)
|
---|
35 | {
|
---|
36 | // Sanity check
|
---|
37 | if (!is_scalar($haystack)) {
|
---|
38 | user_error('strripos() expects parameter 1 to be scalar, ' .
|
---|
39 | gettype($haystack) . ' given', E_USER_WARNING);
|
---|
40 | return false;
|
---|
41 | }
|
---|
42 |
|
---|
43 | if (!is_scalar($needle)) {
|
---|
44 | user_error('strripos() expects parameter 2 to be scalar, ' .
|
---|
45 | gettype($needle) . ' given', E_USER_WARNING);
|
---|
46 | return false;
|
---|
47 | }
|
---|
48 |
|
---|
49 | if (!is_int($offset) && !is_bool($offset) && !is_null($offset)) {
|
---|
50 | user_error('strripos() expects parameter 3 to be long, ' .
|
---|
51 | gettype($offset) . ' given', E_USER_WARNING);
|
---|
52 | return false;
|
---|
53 | }
|
---|
54 |
|
---|
55 | // Initialise variables
|
---|
56 | $needle = strtolower($needle);
|
---|
57 | $haystack = strtolower($haystack);
|
---|
58 | $needle_fc = $needle{0};
|
---|
59 | $needle_len = strlen($needle);
|
---|
60 | $haystack_len = strlen($haystack);
|
---|
61 | $offset = (int) $offset;
|
---|
62 | $leftlimit = ($offset >= 0) ? $offset : 0;
|
---|
63 | $p = ($offset >= 0) ?
|
---|
64 | $haystack_len :
|
---|
65 | $haystack_len + $offset + 1;
|
---|
66 |
|
---|
67 | // Reverse iterate haystack
|
---|
68 | while (--$p >= $leftlimit) {
|
---|
69 | if ($needle_fc === $haystack{$p} &&
|
---|
70 | substr($haystack, $p, $needle_len) === $needle) {
|
---|
71 | return $p;
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | return false;
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | ?> |
---|