note 55915 added to function.explode

From: Date: Wed, 17 Aug 2005 16:04:59 +0000
Subject: note 55915 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-93799@lists.php.net to get a copy of this message
So just incase anyone needs to explode something like a vi formated file with multiple spaces between text/number elements. This will make sure only the text elements are exploded to the resultant array. <?php function trimExplode($on, $str) { $sArray = explode($on,$str); $finalArray = array(); foreach($sArray as $s) if(strcmp($s,"")!=0) $finalArray[] = trim($s); return($finalArray); } ?> Here is an example of using trimExplode: <?php $on = " "; $str = "Test Test1 Test2"; $result = trimExplode($on, $str); foreach($result as $r) echo $r.chr(10); ?> Output: Test Test1 Test2 ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55915 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55915&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55915&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55915&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55915&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55915&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55915&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55915&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93799) next »