note 34009 deleted from function.explode by colder

From: Date: Tue, 21 Nov 2006 09:34:07 +0000
Subject: note 34009 deleted from function.explode by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-119927@lists.php.net to get a copy of this message
Note Submitter: ralfoide at yahoo dat com ---- Using 1 or less for the "limit" may not yield the result you expect. I'm using PHP 4.1.2 I had surprising results when using explode() or split() with a "limit" of 0 or 1: in this case the returned array contains one entry with the full "remaining" string. Ex: $a = explode("/", "a/b/c", 1); var_dump($a); => array(1) { [0]=> string(5) "a/b/c" } $a = explode("/", "a/b/c", 2); var_dump($a); => array(2) { [0]=> string(1) "a" [1]=> string(3) "b/c" } Using limit=0 behaves as in limit=1 above. It seems the implementation uses limit as the number of elements to return, including the "remaining string", whereas the doc seems to describe it as indicating the number of separators to process (i.e. the resulting array should contain limit+1 entries).

« previous php.notes (#119927) next »