<?php
$str = '1000 - 2000';
$str = preg_replace('/\s+/', '', $str);
// zero limit
print_r(explode('-',$str,0));
?>
I am trying to get two array items '1000' and '2000' to no avail. What am i doing wrong here?
<?php
$str = '1000 - 2000';
$str = preg_replace('/\s+/', '', $str);
// zero limit
print_r(explode('-',$str,0));
?>
I am trying to get two array items '1000' and '2000' to no avail. What am i doing wrong here?
Drop the third parameter to explode. Setting that third parameter to 0 you essentially get a one element array returned containing the entire string...
PARAMETERS · $delimiter - The boundary string. · $string - The input string. · $limit - If $limit is set and positive, the returned array will contain a maximum of $limit elements with the last element containing the rest of $string. If the $limit parameter is negative, all components except the last -$limit are returned. If the $limit parameter is zero, then this is treated as 1.