note 46387 added to function.explode

From: Date: Sat, 09 Oct 2004 12:56:57 +0000
Subject: note 46387 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-78219@lists.php.net to get a copy of this message
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; } ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46387 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46387&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+46387&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#78219) next »