NYCPHP Meetup

[nycphp-talk] Wiki Style Links

Dan Cech dcech at phpwerx.net
Wed Mar 5 10:36:30 EST 2008


Donald J Organ IV wrote:
> I was wondering if anyone else has done this and if they have the code 
> readily available.
> I want to be able to parse wiki style links such as
> 
> [[page|title]]
> [[page]]
> 
> Any suggestions ??

Something like this might be a start:

$str = preg_replace(
   array(
     '/\[\[([^|\]]+)\]\]/U',
     '/\[\[([^|\]]+)|([^\]]+)\]\]/U',
   ),
   array(
     '<a href="$1">$1</a>',
     '<a href="$1">$2</a>',
   ),
   $str
);

Disclaimer: I haven't tried running this code.

Dan



More information about the talk mailing list