PageRenderTime 38ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/pear/PHP/Compat/Function/stripos.php

http://akelosframework.googlecode.com/
PHP | 73 lines | 34 code | 9 blank | 30 comment | 9 complexity | 520b716b06db543e2bc968699d8b40db MD5 | raw file
Possible License(s): LGPL-2.1
  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. // +----------------------------------------------------------------------+
  17. //
  18. // $Id: stripos.php,v 1.13 2005/05/30 20:33:03 aidan Exp $
  19. /**
  20. * Replace stripos()
  21. *
  22. * @category PHP
  23. * @package PHP_Compat
  24. * @link http://php.net/function.stripos
  25. * @author Aidan Lister <aidan@php.net>
  26. * @version $Revision: 1.13 $
  27. * @since PHP 5
  28. * @require PHP 4.0.0 (user_error)
  29. */
  30. if (!function_exists('stripos')) {
  31. function stripos($haystack, $needle, $offset = null)
  32. {
  33. if (!is_scalar($haystack)) {
  34. user_error('stripos() expects parameter 1 to be string, ' .
  35. gettype($haystack) . ' given', E_USER_WARNING);
  36. return false;
  37. }
  38. if (!is_scalar($needle)) {
  39. user_error('stripos() needle is not a string or an integer.', E_USER_WARNING);
  40. return false;
  41. }
  42. if (!is_int($offset) && !is_bool($offset) && !is_null($offset)) {
  43. user_error('stripos() expects parameter 3 to be long, ' .
  44. gettype($offset) . ' given', E_USER_WARNING);
  45. return false;
  46. }
  47. // Manipulate the string if there is an offset
  48. $fix = 0;
  49. if (!is_null($offset)) {
  50. if ($offset > 0) {
  51. $haystack = substr($haystack, $offset, strlen($haystack) - $offset);
  52. $fix = $offset;
  53. }
  54. }
  55. $segments = explode(strtolower($needle), strtolower($haystack), 2);
  56. // Check there was a match
  57. if (count($segments) === 1) {
  58. return false;
  59. }
  60. $position = strlen($segments[0]) + $fix;
  61. return $position;
  62. }
  63. }
  64. ?>