note 60100 deleted from function.split by felipe

From: Date: Thu, 10 Apr 2008 22:05:40 +0000
Subject: note 60100 deleted from function.split by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-138126@lists.php.net to get a copy of this message
Note Submitter: shimon at schoolportal dot co dot il ---- <? // ** // * splitslash() // * // * this function enables to split with an escape char; // * // * @since 25/12/05 21:26:00 // * @author Shimon Doodkin // * // * @param $string // * @param $string // * @return Array() // ** function splitslash($split,$str,$esc='\\\\') { $o=explode($split,$str); $oc=count($o); $a=array(); for($i=0;$i<$oc;$i++) { $o2=explode($esc.$esc,$o[$i]); $o2c=count($o2); if($o2[$o2c-1][strlen($o2[$o2c-1])-1]==$esc) { $o2[$o2c-1]=substr($o2[$o2c-1],0,-1); if($i+1<$oc) { $o[$i+1]=join($esc.$esc,$o2).$split.$o[$i+1]; } else { //echo "error"; $a[]=join($esc,$o2); //do like ok } } else { $a[]=join($esc,$o2); } } return $a; } // example: $r=splitslash("NA","mooNAmooNAma\\\\ma\\NA"); print_r($r); //output: /* Array ( [0] => moo [1] => moo [2] => ma\\maNA ) */ ?>

« previous php.notes (#138126) next »