[Pmwiki-users] regexp for free links?

Patrick R. Michaud pmichaud
Wed Jul 7 09:22:28 CDT 2004


On Wed, Jul 07, 2004 at 11:48:57AM +0200, Jody Foo wrote:
> I would like to use the PmWiki notation, but I just can't get it
> right. So, my question is, how do I get FreeLink from {{free link}}? I
> tried looking at the sources, but could not understand them..

The code for handling free links in 2.0 is probably a better starting
point for figuring out how it works.  Assuming that $x contains something
like "{{free link}}", here's a way to turn it into a page name:

    # extract the page name into $match[1]   
    preg_match("/\\{\\{(.*?)\\}\\}/",x,$match);
    # convert any sequences of non-pagename character into a space
    $a = preg_replace("/[^-[:alnum:]]+/",' ',$match[1]);
    # capitalize each word of the string
    $b = ucwords($a);
    # remove the spaces
    $c = str_replace(' ','',$b);

Thus, if $x starts out as "{{free link}}", then $a is "free link", 
$b is "Free Link", and $c is "FreeLink".

The 2.0 code for converting strings to page names is actually held in
the MakePageName() function, which will convert any string into a
valid pagename.  In the pmwiki.php 2.0 code the above steps are combined
into a single statement, as in

$c=str_replace(' ','',ucwords(preg_replace("/[^-[:alnum:]]+/",' ',$match[1])));

In the PmWiki 1.0 code, it's the FreeLink() function that converts 
"{{page name}}" into PageName.

Pm




More information about the pmwiki-users mailing list