/akelos_utils/contrib/pear/PHP/Compat/Function/strripos.php

https://github.com/ameximes/akelos · PHP · 79 lines · 39 code · 8 blank · 32 comment · 8 complexity · 56a986fa60a681488bc88fc9efef34c4 MD5 · raw file

  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. * Replace strripos()
  22. *
  23. * @category PHP
  24. * @package PHP_Compat
  25. * @link http://php.net/function.strripos
  26. * @author Aidan Lister <aidan@php.net>
  27. * @version $Revision: 1.24 $
  28. * @since PHP 5
  29. * @require PHP 4.0.0 (user_error)
  30. */
  31. if (!function_exists('strripos')) {
  32. function strripos($haystack, $needle, $offset = null)
  33. {
  34. // Sanity check
  35. if (!is_scalar($haystack)) {
  36. user_error('strripos() expects parameter 1 to be scalar, ' .
  37. gettype($haystack) . ' given', E_USER_WARNING);
  38. return false;
  39. }
  40. if (!is_scalar($needle)) {
  41. user_error('strripos() expects parameter 2 to be scalar, ' .
  42. gettype($needle) . ' given', E_USER_WARNING);
  43. return false;
  44. }
  45. if (!is_int($offset) && !is_bool($offset) && !is_null($offset)) {
  46. user_error('strripos() expects parameter 3 to be long, ' .
  47. gettype($offset) . ' given', E_USER_WARNING);
  48. return false;
  49. }
  50. // Initialise variables
  51. $needle = strtolower($needle);
  52. $haystack = strtolower($haystack);
  53. $needle_fc = $needle{0};
  54. $needle_len = strlen($needle);
  55. $haystack_len = strlen($haystack);
  56. $offset = (int) $offset;
  57. $leftlimit = ($offset >= 0) ? $offset : 0;
  58. $p = ($offset >= 0) ?
  59. $haystack_len :
  60. $haystack_len + $offset + 1;
  61. // Reverse iterate haystack
  62. while (--$p >= $leftlimit) {
  63. if ($needle_fc === $haystack{$p} &&
  64. substr($haystack, $p, $needle_len) === $needle) {
  65. return $p;
  66. }
  67. }
  68. return false;
  69. }
  70. }
  71. ?>