note 63749 deleted from function.explode by bjori

From: Date: Thu, 30 Mar 2006 10:13:07 +0000
Subject: note 63749 deleted from function.explode by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-107008@lists.php.net to get a copy of this message
Note Submitter: Nathaniel Gibson ---- /* I created a function like the one listed below. It explodes a string that also has encapsulated delimiters, like a CSV. It also includes being able to tell the function what the encapsulator string is, plus set a limit like the explode function. Another handy feature is that, like explode, you can have multi-character delimiter and encapsulator strings. */ function lit_explode($exstr,$string,$literal,$limit=0){ $litlen = strlen($literal); $exlen = strlen($exstr); $p = 0; for ($i=0;$i<strlen($string);$i++){ $e = substr($string,$i,1); $g = substr($string,$i,$exlen); $a = substr($string,$i,$litlen); if ($a == $literal && $liton){ $liton = false; if ($litlen > 1) $i += $litlen-1; }elseif ($a == $literal && !$liton){ $liton = true; if ($litlen > 1) $i += $litlen-1; }elseif ($g == $exstr && !$liton){ if ($limit && $p < $limit || !$limit) $outarr[] = $txt; $p++; if ($exlen > 1) $i += $exlen-1; $txt = ''; }else{ $txt .= $e; } } return $outarr; } /*Enjoy :)*/

« previous php.notes (#107008) next »