note 60102 added to function.split

From: Date: Mon, 26 Dec 2005 22:10:23 +0000
Subject: note 60102 added to function.split
Groups: php.notes 
Request: Send a blank email to php-notes+get-100754@lists.php.net to get a copy of this message
<?php // ** // * splitslash() // * // * @since 25/12/05 21:26:00 // * @author shimon doodkin // * // * @param $string split by // * @param $string stlitted string // * @param $integer maximum number on array values to return // * @param $string escape character // * @return Array() // ** function splitslash($split,$str,$max=0,$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(strlen($o2[$o2c-1])>1&&$o2[$o2c-1][strlen($o2[$o2c-1])-1]==$esc) { if($i+1<$oc) { $o2[$o2c-1]=substr($o2[$o2c-1],0,-1); $o[$i+1]=join($esc.$esc,$o2).$split.$o[$i+1]; } else { //echo "error"; if(count($a)-1>-1) $a[count($a)-1].=join($esc,$o2); else return array(join($esc,$o2)); } } else { $a[]=join($esc,$o2); } if($max>0&&count($a)==$max) { $i++; for(;$i<$oc;$i++) { $a[$max-1].=$split.str_replace($esc.$esc,$esc,$o[$i]); } break; } } return $a; } // example //$r=splitslash("NA","mooNAmooNAma\\\\ma\\NAfdsfasd"); //print_r($r); ?> ---- Manual Page -- http://www.php.net/manual/en/function.split.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60102 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60102&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60102&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60102&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60102&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60102&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60102&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60102&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60102&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#100754) next »