Parsing plain text that contains custom conditionals
<p>I presume this is a weird sort of thing that I'm looking for.</p>

<p>I have the following text string:</p>

<pre><code>$string = "The compass is pointing &lt;north|south|east|west&gt; towards &lt;London|Paris|Rome&gt;";
</code></pre>

<p>Somehow I want to parse this to obtain any of the following outputs:</p>

<ul>
<li>The compass is pointing north towards Paris</li>
<li>The compass is pointing south towards London</li>
<li>The compass is pointing east towards Rome</li>
<li>The compass is pointing east towards London</li>
<li>Etc.</li>
</ul>

<p>For each set of &lt; > in the text string I need to convert the contents into an array (using <code>explode("|",$string)</code>?), then run <code>array_rand</code> on that array to get the key for the option we will display, then just read the array and return that value.</p>

<p>The problem is, I have very next to no experience with text parsing, but I'd guess you'd use <code>preg_replace</code> in this type of problem.</p>

<p>I'd appreciate if anyone could help me get started.</p>
