Explode string except where surrounded by parentheses?
<p>I'm trying to explode a string by vertical bars. That's the easy part. However, I DON'T want the split to affect substrings that are surrounded by parentheses. That means I need a string such as:</p>

<pre><code>Hello (sir|maam).|Hi there!
</code></pre>

<p>to explode into:</p>

<pre><code>Array
(
    [0] =&gt; Hello (sir|maam).
    [1] =&gt; Hi there!
)
</code></pre>

<p>By using the normal explode function, I don't believe there is a way to tell it to ignore that bar surrounded by the parentheses. However, I have some ideas.</p>

<p>I know that it would be possible to do this by exploding the string normally, and then looping through the array and merging everything between strings that contain <code>(</code> to the closing string that contains <code>)</code>. However, I have a feeling that there should be a more elegant way of achieving this.</p>

<p>Am I right? Is there  a less code-intensive means of spliting a string into an array given these restrictions?</p>
