15 May 2001 eskimoses   » (Journeyer)

Aargh. I like PHP. I love Perl regular expressions. Hence, I love preg_match and preg_replace.

Or I used to. Y'see, preg_replace has Perl's cool "evaluate the right-hand-side as though it were code" operator: 'e'. Coolness. So I write a whole mess of functions to do all sorts of cool transformations of wiki markup into HTML.

Except, if the right hand side is code, preg_replace has no consistent means of representing backreferences! Try this, kiddos:

function f($x) { print $x; }
$s = "a' \" \\b";
$s = preg_replace('/a(.*)b/e', 'f("$1")', $s);

Yeppers, it bombs. Seems that, while they remembered to escape quotes, they forgot to escape backslashes themselves. Oops.

I just wish they could treat that $1 the way Perl does it: like a variable and not like a "replace this token with the string itself"! Tell me that wouldn't make lots more sense. :-)

Thanks to the wonders of still-open PHP bug reports and very slow upgrades on virtual hosts, it looks like I'm doomed to keep my wiki engine in perpetual beta for quite a bit longer (been lingering on this for nearly two months now, no sign of relief). Other than this it's ready for release! Grr.

That was therapeutic. :-) Except it doesn't get me closer to a solution. I'm almost ready to ditch PHP altogether. Perl or Python, anyone?

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!