title: PHP explode string into array with space delimiter when string has multiple spaces?
body: <p>My PHP code below will explode a string into array.  It allows to use multiple delimiters for detecting where the array values should be  from the string.</p>
  
  <p>In the demo one of the delimiter values is a space.  The problem is if the string has more than 1 consecutive space, it will generate empty array values.</p>
  
  <p>For example <code>key key2 key3  key4</code> would generate array with:  </p>
  
  <pre><code>Array
  (
      [0] =&gt; key
      [1] =&gt; key2
      [2] =&gt; key3
      [3] =&gt; 
      [4] =&gt; key4
  )
  </code></pre>
  
  <p>and the desired output is:  </p>
  
  <pre><code>Array
  (
      [0] =&gt; key
      [1] =&gt; key2
      [2] =&gt; key3
      [4] =&gt; key4
  )
  </code></pre>
  
  <p>How can I fix this?</p>
  
  <hr>
  
  <pre><code>/**
   * Explode a string into array with multiple delimiters instead of the default 1 delimeter that explode() allows!
   * @param  array $delimiters - array(',', ' ', '|') would make a string with spaces, |, or commas turn into array
   * @param string $string  text with the delimeter values in it that will be truned into an array
   * @return array - array of items created from the string where each delimiter  in string made a new array key
   */
  function multiexplode ($delimiters, $string) {
      $ready = str_replace($delimiters, $delimiters[0], $string);
      $array = explode($delimiters[0], $ready);
      $array = array_map('trim', $array);
      return  $array;
  }
  
  $tagsString  = 'PHP JavaScript,WebDev Apollo   jhjhjh';
  $tagsArray = multiexplode(array(',',' '), $tagsString);
  print_r($tagsArray);
  </code></pre>
  
  <hr>
  
  <p><strong>Output array</strong>  </p>
  
  <pre><code>Array
  (
      [0] =&gt; PHP
      [1] =&gt; JavaScript
      [2] =&gt; WebDev
      [3] =&gt; Apollo
      [4] =&gt; 
      [5] =&gt; 
      [6] =&gt; jhjhjh
  )
  </code></pre>