爆炸功能分隔符空白区域

<?php

$str = '1000 - 2000';
$str = preg_replace('/\s+/', '', $str);
// zero limit
print_r(explode('-',$str,0));


?>  

http://ideone.com/rFvgZI

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.

This will do

$arr = preg_split('/\s*-\s*/', $str);

This is splitting the given string around (zero or more white spaces(\s*) + one hyphen + zero or more white spaces(\s*)).

What about just that (for all spaces):

<?php
    $str = '1000 - 2000';
    $tmp = explode('-', preg_replace('/\s+/', '', $str));
    var_dump($tmp);
?>