[pmwiki-users] Conditional Markup enhancement

Patrick R. Michaud pmichaud at pobox.com
Wed Mar 2 09:51:42 CST 2005


On Wed, Mar 02, 2005 at 08:08:36AM +0100, Dominique Faure wrote:
> 
> Could you please post here the code of your ParseArgs function then we 
> could try and understand ourself, thanks.

Sure, here it is.  It's also available in 2.0.beta24 and beta25 
(just released, about to be announced).

I'm also planning to write a Cookbook page that describes the ParseArgs
function and provides an input box where people can see how different
input strings would be parsed.

    function ParseArgs($x) {
      $z = array();
      preg_match_all('/([-+]|(?>(\\w+)[:=]))?("[^"]*"|\'[^\']*\'|\\S+)/',
        $x, $terms, PREG_SET_ORDER);
      foreach($terms as $t) {
        $v = preg_replace('/^([\'"])?(.*)\\1$/', '$2', $t[3]);
        if ($t[2]) { $z['#'][] = $t[2]; $z[$t[2]] = $v; }
        else { $z['#'][] = $t[1]; $z[$t[1]][] = $v; }
        $z['#'][] = $v;
      }
      return $z;
    }
    
    
Pm



More information about the pmwiki-users mailing list