[pmwiki-users] preg vs str_replace

Patrick R. Michaud pmichaud at pobox.com
Thu Oct 12 21:41:47 CDT 2006


On Thu, Oct 12, 2006 at 10:37:04PM -0400, The Editor wrote:
> Can someone explain the advantage in terms of php code between
> 
> preg_replace('/\\(:/', '(:', $value);
> 
> and
> 
> str_replace('(:', '(:', $value);

The str_replace function is faster, but it can be only used to search
and replace fixed strings.  The preg_function can find things matching
arbitrary patterns and manipulate them in various ways (including executing
code), but it's somewhat slower.

> Also it seems I'm getting pages included that are read protected.
> Isn't that supposed to not be possible?  Very strange...

The ReadPage() function doesn't do _any_ checking for authorization
to access a page.  To read a page only if the visitor has authorization
for the page, use RetrieveAuthPage() instead.

(I'll note in passing that the built-in functions that do page text
variable handling use RetrieveAuthPage(), so that people cannot use
page text variables to circumvent read restrictions.)

Pm




More information about the pmwiki-users mailing list