I have splited some text and got a bunch of numbers, the prob. is that the numbers can have "spaces" next to them. ' 5' and so on can I somehow use foreach and trim these numbers?
Thanks.
$del = "|"; $string = " 1| 2| 3| 4| 5"; $arr = split("|",$string); for($i=0$ < count($string);$i++) {$arr[$i]=trim($arr[$i]);}
// both are same reset ($arr); while (list($key, $value) = each ($arr)) { $arr[$key] = trim($value); }
<?php $separator = ','; $string = '3, 5, 7, 9, 10';
$string = explode($separator,$string); foreach ($string as $number) { $number = trim($number); echo "$number<br />"; } ?>
This will print: 3 5 7 9 10