Stripos for PHP4

One of the more useful functions introduced in PHP 5 was stripos(). I have got so used to using it that I sometimes encounter errors when I use PHP 4 on some of the sites I own that still use that version of PHP.

To this end, I use a nice little function to remove this issue and make code portable for servers using PHP 4 or 5.


<?php
if (!function_exists("stripos")) {
    function 
stripos($haystack$needle$offset=0) {
        return 
strpos(strtolower($haystack), strtolower($needle), $offset);
    }
}


Simple, huh?

Comments

Thanks!

I was trying to solve this in a lot more difficult way. You just saved me a lot of time (which I can spend writing this comment :-) )

THANKS!!!

I can only say THANKS for that simple help... ;)

thanks

thanks for this example

Jamie, This is magic - i

Jamie,

This is magic - i have made a wordpress plugin using the function which obviously breaks on php4 sites.

Cheers for this, reaslly useful.

Glad you found it useful

Glad you found it useful -
of course I cannot take credit for it,
but I have found it very handy in the past!!

Good luck..

Br

Jamie

Unraveling the mysteries of the web
http://www.skiffie.com

Syndicate content