[pmwiki-users] ZAP nearly ready...

Patrick R. Michaud pmichaud at pobox.com
Mon Oct 23 13:23:51 CDT 2006


The Editor wrote:

>Oh one extra question I forgot to ask before...
>
>Can someone help rewrite this expression pattern so it does not
>execute for something like {$var}, {=$var} or {$:var}, etc (ie with a
>$ sign), but it does execute for {var}.
>
>$_POST[$field] = preg_replace('/\\{(.*?)\\}/e', "\$_POST[$1]", $value);
>
>I can't seem to figure out how to do negatives...

I strongly recommend _against_ using "{var}" as the markup for
this, because it will conflict with many other uses of braces
as markup, including {-deleted-}, {+inserted+}, {=stickynote=},
{abbr|abbreviation}, and possibly others that other recipes may
wish to use.

If you're intending to simply grab the values of posted fields, 
I'd recommend {$?var} or {$!var} or something like that.  If nothing 
else, at least be consistent with the HttpVariables recipe 
(which uses {$|var} to get $_POST values).  But trying to grab
{var} might just run into problems.

However, to answer your question, there are several ways to
look at it:

    '/\\{(\\w+)\\}/e'      only allow alphanumeric chars in braces
    '/\\{([^$]+)\\}/e'     anything except $
    '/\\{([^-+$]+)\\}/e'   anything except -, +, $

Pm




More information about the pmwiki-users mailing list