note 46387 deleted from function.explode by tomsommer

From: Date: Sat, 09 Oct 2004 20:23:02 +0000
Subject: note 46387 deleted from function.explode by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-78242@lists.php.net to get a copy of this message
Note Submitter: mcuadros at n0nam3 dot com ---- If u have a string like "37, 0, 'mysql,mssql,oracle', '1'" and u use explode u get some like: Array ( [0] => 37 [1] => 0 [2] => 'mysql [3] => mssql [4] => oracle' [5] => '1' ) but if u use this function will get: Array ( [0] => 37 [1] => 0 [2] => 'mysql,mssql,oracle' [3] => '1' ) The function: function explode_adv($separator, $limit_strings,$string ) { $len = strlen($separator); for ( $i = 0; ; $i++ ) { if ( ( $pos = strpos( $string, $separator ) ) === false ) { $result[$i] = $string; break; } if ( substr( trim($string), 0, strlen($limit_strings) ) == $limit_strings ) { if ( ($pos = strpos( $string, $separator ,strpos( trim($string), $limit_strings,strlen($limit_strings) +1 ) )) === false ) { $result[$i] = $string; break; } } $result[$i] = substr( $string, 0, $pos ); $string = substr( $string, $pos + $len ); } return $result; }

« previous php.notes (#78242) next »