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: Tom Buskens <ortega@php.net> | |
---|
16 | // | Aidan Lister <aidan@php.net> | |
---|
17 | // +----------------------------------------------------------------------+ |
---|
18 | // |
---|
19 | // $Id$ |
---|
20 | |
---|
21 | |
---|
22 | /** |
---|
23 | * Replace substr_compare() |
---|
24 | * |
---|
25 | * @category PHP |
---|
26 | * @package PHP_Compat |
---|
27 | * @link http://php.net/function.substr_compare |
---|
28 | * @author Tom Buskens <ortega@php.net> |
---|
29 | * @author Aidan Lister <aidan@php.net> |
---|
30 | * @version $Revision: 1.5 $ |
---|
31 | * @since PHP 5 |
---|
32 | * @require PHP 4.0.0 (user_error) |
---|
33 | */ |
---|
34 | if (!function_exists('substr_compare')) { |
---|
35 | function substr_compare($main_str, $str, $offset, $length = null, $case_insensitive = false) |
---|
36 | { |
---|
37 | if (!is_string($main_str)) { |
---|
38 | user_error('substr_compare() expects parameter 1 to be string, ' . |
---|
39 | gettype($main_str) . ' given', E_USER_WARNING); |
---|
40 | return; |
---|
41 | } |
---|
42 | |
---|
43 | if (!is_string($str)) { |
---|
44 | user_error('substr_compare() expects parameter 2 to be string, ' . |
---|
45 | gettype($str) . ' given', E_USER_WARNING); |
---|
46 | return; |
---|
47 | } |
---|
48 | |
---|
49 | if (!is_int($offset)) { |
---|
50 | user_error('substr_compare() expects parameter 3 to be long, ' . |
---|
51 | gettype($offset) . ' given', E_USER_WARNING); |
---|
52 | return; |
---|
53 | } |
---|
54 | |
---|
55 | if (is_null($length)) { |
---|
56 | $length = strlen($main_str) - $offset; |
---|
57 | } elseif ($offset >= strlen($main_str)) { |
---|
58 | user_error('substr_compare() The start position cannot exceed initial string length', |
---|
59 | E_USER_WARNING); |
---|
60 | return false; |
---|
61 | } |
---|
62 | |
---|
63 | $main_str = substr($main_str, $offset, $length); |
---|
64 | $str = substr($str, 0, strlen($main_str)); |
---|
65 | |
---|
66 | if ($case_insensitive === false) { |
---|
67 | return strcmp($main_str, $str); |
---|
68 | } else { |
---|
69 | return strcasecmp($main_str, $str); |
---|
70 | } |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | ?> |
---|