1   <?php
  2   /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3   // +----------------------------------------------------------------------+
  4   // | PHP Version 4                                                        |
  5   // +----------------------------------------------------------------------+
  6   // | Copyright (c) 1997-2004 The PHP Group                                |
  7   // +----------------------------------------------------------------------+
  8   // | This source file is subject to version 3.0 of the PHP license,       |
  9   // | that is bundled with this package in the file LICENSE, and is        |
  10   // | available at through the world-wide-web at                           |
  11   // | http://www.php.net/license/3_0.txt.                                  |
  12   // | If you did not receive a copy of the PHP license and are unable to   |
  13   // | obtain it through the world-wide-web, please send a note to          |
  14   // | license@php.net so we can mail you a copy immediately.               |
  15   // +----------------------------------------------------------------------+
  16   // | Authors: Aidan Lister <aidan@php.net>                                |
  17   // +----------------------------------------------------------------------+
  18   //
  19   // $Id: stripos.php,v 1.1 2004-10-26 18:22:16 kostja Exp $
  20   //
  21  
  22  
  23   /**
  24    * Replace stripos()
  25    *
  26    * @category    PHP
  27    * @package     PHP_Compat
  28    * @link        http://php.net/function.stripos
  29    * @author      Aidan Lister <aidan@php.net>
  30    * @version     $Revision: 1.1 $
  31    * @since       PHP 5
  32    * @require     PHP 4.0.1 (trigger_error)
  33    */
  34   if (!function_exists('stripos'))
  35   {
  36       function stripos ($haystack, $needle, $offset = null)
  37       {
  38           if (!is_scalar($haystack)) {
  39               trigger_error('stripos() expects parameter 1 to be string, ' . gettype($haystack) . ' given', E_USER_WARNING);
  40               return false;
  41           }
  42  
  43           if (!is_scalar($needle)) {
  44               trigger_error('stripos() needle is not a string or an integer.', E_USER_WARNING);
  45               return false;
  46           }
  47  
  48           if (!is_null($offset) && !is_numeric($offset)) {
  49               trigger_error('stripos() expects parameter 3 to be long, ' . gettype($offset) . ' given', E_USER_WARNING);
  50               return false;
  51           }
  52  
  53           // Manipulate the string if there is an offset
  54           $fix = 0;
  55           if (!is_null($offset))
  56           {
  57               if ($offset > 0)
  58               {
  59                   $haystack = substr($haystack, $offset, strlen($haystack) - $offset);
  60                   $fix = $offset;
  61               }
  62           }
  63  
  64           $segments = explode (strtolower($needle), strtolower($haystack), 2);
  65           $position = strlen($segments[0]) + $fix;
  66  
  67           return $position;
  68       }
  69   }
  70  
  71   ?>