[pmwiki-devel] preg dot question...

Patrick R. Michaud pmichaud at pobox.com
Thu Dec 7 19:28:42 CST 2006

On Thu, Dec 07, 2006 at 07:21:32PM -0500, The Editor wrote:
> I have a pattern matching I'm using for a redirect markup called (:forward:).
> It looks like this:
> $x = preg_replace('/\(\:forward ([-.\\w]+)\:\)/e', 'Redirect($1)', $x);
> It works fine BUT
>  when I put (:forward Group.Page:) the value passed to Redirect is
> GroupPage.  The dot disappears.  

You don't have quotes around your $1.  Thus after doing the match,
PHP replaces the $1 with the part in parentheses and sees


and since Group.Page isn't a string, the dot gets lost.  You really

  $x = preg_replace('/\(\:forward ([-.\\w]+)\:\)/e', "Redirect('$1')", $x);

BTW, I've noticed this throughout the ZAP code, where things that
ought to be strings aren't placed in quotes.  That's generally not
a good idea, because one never knows when a word will accidentally
end up being a PHP function or having a meaning other than being
a bareword string.


More information about the pmwiki-devel mailing list