note 55915 deleted from function.explode by victor
| From: | victor@php.net | Date: | Wed, 17 Aug 2005 16:05:51 +0000 |
| Subject: | note 55915 deleted from function.explode by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-93800@lists.php.net to get a copy of this message | ||
Note Submitter: dave at banff dot org
----
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