[pmwiki-users] Version 2.2.0-beta22 - directives (reported by Marc)

Patrick R. Michaud pmichaud at pobox.com
Wed Jan 17 13:51:03 CST 2007


On Wed, Jan 17, 2007 at 06:46:09PM +0000, Andrew Fyfe wrote:
> I think this is the change it's referring to:
> 
> > @@ -951,12 +952,12 @@
> >      }
> >      return;
> >    }
> > -  if (preg_match("/^markup:(.*)$/",$x,$match))
> > -    { print MarkupToHTML($pagename,$match[1]); return; }
> > -  if (preg_match('/^wiki:(.+)$/', $x, $match))
> > -    { PrintWikiPage($pagename, $match[1], 'read'); return; }
> > -  if (preg_match('/^page:(.+)$/', $x, $match))
> > -    { PrintWikiPage($pagename, $match[1], ''); return; }
> > +  if (substr($x, 0, 7) == 'markup:')
> > +    { print MarkupToHTML($pagename, substr($x, 7)); return; }
> > +  if (substr($x, 0, 5) == 'wiki:')
> > +    { PrintWikiPage($pagename, substr($x, 5), 'read'); return; }
> > +  if (substr($x, 0, 5) == 'page:')
> > +    { PrintWikiPage($pagename, substr($x, 5), ''); return; }
> >    echo $x;
> >  }
> 
> But all the change does (as far as I can see) is make use of substr
> instead of preg_match. (substr takes less time than preg_match for this
> simple match).

It's a bit more subtle than that.  :-)

As written above, the preg_match expressions only work on strings 
without newlines in them, because '.' doesn't match newline.
This was the bug that marc originall reported, where he needed
<!--markup:...--> directives to be able to contain newlines.

I could've just added a /s to the end of the regexes to get
the dot to match newlines also, but I decided it was more
straightforward (and efficient) to use substr() here instead.

Thanks!

Pm




More information about the pmwiki-users mailing list