note 68833 deleted from function.explode by bjori
| From: | bjori@php.net | Date: | Mon, 25 Sep 2006 08:05:40 +0000 |
| Subject: | note 68833 deleted from function.explode by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-117565@lists.php.net to get a copy of this message | ||
Note Submitter: Rowan Lewis
----
I hate correcting myself, but oh well: the ExplodeI function posted below works perfectly, but there
is a problem, its slow, amazingly after performing some speed tests, I discovered that it was faster
to use regular expressions instead:
<?php
function ExplodeI($Saperator, $String, $Limit = Null) {
if (!$Saperator) { return false; }
$Saperator = Preg_Quote($Saperator, "/");
// Create a different set, depending on what the limit is:
if ($Limit > 0) {
$Return = Preg_Split("/{$Saperator}/i", $String, $Limit);
} else {
$Return = Preg_Split("/{$Saperator}/i", $String);
}
// Deal with negative limits:
if ($Limit < 0) {
return Array_Slice($Return, 0, $Limit);
}
return $Return;
}
?>