title: How to extract substrings with delimiters from a string in php
body: <p>I would like to remove substrings from a string that have delimiters.</p>
  
  <p>Example:</p>
  
  <pre><code>$string = "Hi, I want to buy an [apple] and a [banana].";
  </code></pre>
  
  <p>How do I get "apple" and "banana" out of this string and in an array? And the other parts of the string "Hi, I want to buy an" and "and a" in another array.</p>
  
  <p>I apologize if this question has already been answered. I searched this site and couldn't find anything that would help me. Every situation was just a little different.</p>