[pmwiki-users] automatic link creation

Patrick R. Michaud pmichaud at pobox.com
Wed Aug 26 09:47:20 CDT 2009

On Wed, Aug 26, 2009 at 02:51:02AM +0200, Melodye Bowers wrote:
> $foo = array('John' => 'http://www.abc.com', 'Sally' => 'http://www.def.com');
> foreach ($foo as $name => $site) {
>    Markup('/\b'.$name.'\b/', '%newwin%'.$site.'%%', ...);
> }
> Does that work?  

It "works", but only for very small numbers of names.  After adding
100 or so such rules the speed of markup processing will degrade 

Better would be to combine all of the names into a single markup rule
(code below is untested, for illustration only):

    $foo = array('John' => 'http://www.abc.com', 
                 'Sally' => 'http://www.def.com');

    Markup('names', 'inline',
      '/\b(' . join('|', array_keys($foo)) . ')\b/e',

It's also possible that one could make use of the $IMap array
for this in config.php (also untested):

    $IMap['John'] = 'http://www.abc.com/';
    $IMap['Sally'] = 'http://www.def.com/';


More information about the pmwiki-users mailing list