I've searched the PHP manual, Stackoverflow, and some forums, but I'm stumped on some PHP logic. Maybe I'm just tired, but I'd really appreciate some assistance or direction on this by anybody.
I have a PHP string, say:
$string = 'cats cat1 cat2 cat3 dogs dog1 dog2 monkey creatures monkey_creature1 monkey_creature2 monkey_creature3';
Eventually, I would ideally like my final output to look something like this, but just getting the array for now is more than fine:
<h2>cats</h2>
<ul>
<li>cat1</li>
<li>cat2</li>
<li>cat3</li>
</ul>
<h2>dogs</h2>
<ul>
<li>dog1</li>
<li>dog2</li>
</ul>
<h2>monkey creatures</h2>
<ul>
<li>monkey_creature1</li>
<li>monkey_creature2</li>
<li>monkey_creature3</li>
</ul>
There's a catch though, sometimes the string will be slightly different:
$string = 'cats cat1 cat2 cat3 cat4 cat5 cats6 dogs dogs1 dogs2 monkey creatures monkey_creature1 lemurs lemur1 lemur2 lemur3';
Anyways, this is my first question on Stackoverflow, and thanks in advance for all the help guys!
Edit: I'm working under some certain limitations, and I can't change any code before the string. I know in advanced all the parents ('cats', 'dogs', 'lemurs', 'monkey creatures (with space)'