note 63749 added to function.explode
| From: | NathanielGibson at osu1 dot php dot net | Date: | Wed, 29 Mar 2006 22:11:40 +0000 |
| Subject: | note 63749 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-106979@lists.php.net to get a copy of this message | ||
/* 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 :)*/
----
Server IP: 216.194.113.175
Probable Submitter: 69.252.206.39
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.explode.php
Edit -- http://master.php.net/note/edit/63749
Del: integrated -- http://master.php.net/note/delete/63749/integrated
Del: useless -- http://master.php.net/note/delete/63749/useless
Del: bad code -- http://master.php.net/note/delete/63749/bad+code
Del: spam -- http://master.php.net/note/delete/63749/spam
Del: non-english -- http://master.php.net/note/delete/63749/non-english
Del: in docs -- http://master.php.net/note/delete/63749/in+docs
Del: other reasons-- http://master.php.net/note/delete/63749
Reject -- http://master.php.net/note/reject/63749
Search -- http://master.php.net/manage/user-notes.php