开发者

Matching innermost braces with regex or strpos?

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->Tab开发者_开发问答le->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:

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


Just add the opening brace to your negated character class:

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


var $validate= array(
'name'=>array(
'notEmpty'  =>array(
    'rule'=>'notEmpty',
    'message'=>'Please Enter The Name'
),
'isUnique'  =>array(
    'rule'=>'isUnique',
    'message'=>'Name Already Exist' 
)
),
'address'=>array(
'rule'=>'notEmpty',
'message'=>'Please Enter The Address')

);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜