note 37563 modified in function.explode by didou

From: Date: Thu, 20 Nov 2003 10:09:45 +0000
Subject: note 37563 modified in function.explode by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-60673@lists.php.net to get a copy of this message
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); } --was-- (please remove my last post! it has a big bug on it) 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://www.php.net/manual/en/function.explode.php

« previous php.notes (#60673) next »