title: Regular expression as delimiter in explode()
body: <p>So I have a string which I'm turning into an array but I want to separate each word using a regex. I'm matching a whole word using the below function.</p>
  
  <pre><code>function substr_count_array($haystack, $needle)
  {
       $initial = 0;
       $bits = explode(' ', $haystack);
  
       foreach ($needle as $substring) 
       {
          if (!in_array($substring, $bits))
          {
              continue;
          }
  
          $initial += substr_count($haystack, $substring);
       }
  
       return $initial;
  }
  </code></pre>
  
  <p>The problem is that it matches the string <code>animal</code> for example but not <code>animals</code>. And if I do a partial match like this:</p>
  
  <pre><code>function substr_count_array2($haystack, $needle)
  {
       $initial = 0;
  
       foreach ($needle as $substring) 
       {
            $initial += substr_count($haystack, $substring);
       }
  
       return $initial;
  }
  </code></pre>
  
  <p>It also matches, let's say, <code>a</code> since it's contained withing the word <code>animals</code> and returns <code>2</code>. How do I <code>explode()</code> using a regular expression as a delimiter so that I may, for example, match every string that has a length of 5-7 characters?</p>
  
  <p>Explained simpler:</p>
  
  <pre><code>$animals = array('cat','dog','bird');
  $toString = implode(' ', $animals);
  $data = array('a');
  
  echo substr_count_array($toString, $data);
  </code></pre>
  
  <p>If I search for a character such as <code>a</code>, it gets through the check and validates as a legit value because <code>a</code> is contained within the first element. But if I match whole words exploded by a space, it omits them if they are not separated by a space. Thus, I need to separate with a regular expression that matches anything <strong>AFTER</strong> the string that is to be matched.</p>