views:

111

answers:

1

I have a sort of mini parsing syntax I made up to help me streamline my view code in cakephp. Basically I have created a table helper which, when given a dataset and (optionally) a set of options for how to format the data will render out a table, as opposed to me looping though the data and editing it manually.

It allows the user to be as complex or as simple as they like, it can get pretty powerful. However, In order to achieve this I had to make a simple parsing syntax. As a quick example the user would do something like so:

$this->Table->data = $userData;
$this->Table->elements['td']['data'] = array(
    '{:User.username:}',
    '{:User.created:}' => array('Time::nice')
);
echo $this->Table->render();

And when rendering the table would then generate:

<table>
    <tbody>
        <tr><td>rich97</td><td>Sun 21st 02:30pm</td></tr>
    </tbody>
</table>

The problem occurs then I try to nest the braces like so:

{:User.levels.iconClasses.{:User.access:}:}

Is there anyway I can only get the inner most brackets on the first time round and loop though until there are no matches? Or even do it in one go? Or even better use strpos?

Here is my regex as it stands:

 '/\{\:([^}]+)\:\}/'
+1  A: 

Just add the opening brace to your negated character class:

'/\{:([^{}]+):\}/'
Alan Moore
Thank you, works perfectly!
rich97