note 81909 deleted from function.explode by tularis
| From: | tularis@php.net | Date: | Mon, 27 Oct 2008 13:03:39 +0000 |
| Subject: | note 81909 deleted from function.explode by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145810@lists.php.net to get a copy of this message | ||
Note Submitter: ben dot 1plus1 at gmail dot com
----
I rewrote explode() so it'll ignore separators that come after a backslash.
<?php
function dexplode($sep,$str){// explode() except $sep's that follow "\" are ignored
$retarr=array();
$thisstr="";
$x=0;
$arrnum=0;
while($x<strlen($str)){
if($str{$x}=="\\"){
if($str{$x+1}=="\\"){
$thisstr.="\\";
$x+=2;
}elseif($str{$x+1}==$sep){
$thisstr.=$sep;
$x+=2;
}else{
$thisstr.="\\";
$x++;
}
}elseif($str{$x}==":"){
$retarr[$arrnum]=$thisstr;
$arrnum++;
$x++;
$thisstr="";
}else{
$thisstr.=$str{$x};
$x++;
}
}
$retarr[$arrnum]=$thisstr;
return $retarr;
}
?>