note 37563 modified in function.explode by aidan
| From: | aidan@php.net | Date: | Sun, 27 Jun 2004 14:10:52 +0000 |
| Subject: | note 37563 modified in function.explode by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-71909@lists.php.net to get a copy of this message | ||
here is a tested case-insensitive explode I named it explodei().works cool :-)
<?php
function explodei($separator, $string, $limit = false )
{
$len = strlen($separator);
for ( $i = 0; ; $i++ )
{
if ( ($pos = stripos( $string, $separator )) === false || ($limit !== false && $i
> $limit - 2 ) )
{
$result[$i] = $string;
break;
}
$result[$i] = substr( $string, 0, $pos );
$string = substr( $string, $pos + $len );
}
return $result;
}
?>
If your php version is under 5, you'll need to add stripos() to your script.
See http://php.net/function.stripos
--was--
here is a tested case-insensitive explode I named it explodei().works cool :-)
function explodei($separator, $string, $limit = false )
{
$len = strlen($separator);
for ( $i = 0; ; $i++ )
{
if ( ($pos = stripos( $string, $separator )) === false || ($limit !== false && $i >
$limit - 2 ) )
{
$result[$i] = $string;
break;
}
$result[$i] = substr( $string, 0, $pos );
$string = substr( $string, $pos + $len );
}
return $result;
}
if your php version is under 5, paste below function in your code as it's needed for explodei:
strpos(), case-insensitive :
function stripos( $haystack, $needle, $start = 0)
{
$haystack = strtolower ( substr($haystack, $start) );
$needle = strtolower ( $needle );
return strpos( $haystack, $needle);
}
http://php.net/manual/en/function.explode.php