note 73562 added to function.explode

From: Date: Thu, 01 Mar 2007 16:09:13 +0000
Subject: note 73562 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-123983@lists.php.net to get a copy of this message
A quick gotcha that had me head scratching for a while.... If the delimiter occurs right at the end of the string there will be an extra array element (an empty string): <?php $str = "aaa^elephant^chocolate^albatross^"; $arr = explode ("^", $str); echo ("Array length: ".count($arr)); ?> --------------------------------- Array length: 5 ---- Server IP: 194.145.210.3 Probable Submitter: 62.252.0.5 (proxied: 86.1.0.164) ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- https://master.php.net/note/edit/73562 Del: integrated -- https://master.php.net/note/delete/73562/integrated Del: useless -- https://master.php.net/note/delete/73562/useless Del: bad code -- https://master.php.net/note/delete/73562/bad+code Del: spam -- https://master.php.net/note/delete/73562/spam Del: non-english -- https://master.php.net/note/delete/73562/non-english Del: in docs -- https://master.php.net/note/delete/73562/in+docs Del: other reasons-- https://master.php.net/note/delete/73562 Reject -- https://master.php.net/note/reject/73562 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123983) next »