note 92045 deleted from function.explode by danbrown
| From: | danbrown@php.net | Date: | Tue, 07 Jul 2009 01:29:01 +0000 |
| Subject: | note 92045 deleted from function.explode by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-157991@lists.php.net to get a copy of this message | ||
Note Submitter: neG
----
You need function that skips delimeter check if needed?
(There was one posted above, but as I tested, it didn't work correctly as it should)
Thusand times of:
explodeSkipNeeded():1.866 sec
explode():0.04 sec
(On PC, 1,5 Ghz AMD Sempron)
<?php
function explodeSkipNeeded($delimeter, $holder, $string){//neG
for($i = 0; $i < strlen($string); $i++){
$char = $string[$i];
if($char == $holder && $string[$i-1] != '\\'){
$inHolder = (!$inHolder) ? true : false;
}else{
if ($char == $delimeter && !$inHolder){
$ret[] = $str;
unset($str);
}else{
$str .= $char;
}
}
}
$ret[] = stripslashes($str);
return $ret;
}
print_r($base->explodeSkipNeeded(';', '"',
'multiselect;"style=\"background=url(\'img.jpg\');
color:red;\""'));
#Output would be:
Array
(
[0] => multiselect
[1] => style="background=url('img.jpg'); color:red;"
)
?>