Parsing Tags, converting bracketed phrases into HREF links
Posted: Mon Feb 06, 2006 6:16 pm
I am attempting to create a quick and dirty code parser for my personal wiki project, similar to how Wikipedia parses phrases that are surrounded by double brackets. I have looked at how Mediawiki parses, but thier method is far to complex for me to easilly understand. Basically, I'd like to use some sort of str_replace (or something similar) on a variable, have it look for phrases that begin with [[ and end with ]], and have it replace them with href links to a specific url.
Basically, I want to turn the following...
into...
Unfortunately, I cannot figure out the proper way to parse the code. I have been looking at str_replace, but ereg_replace and preg_replace also look like possibilities. Can anyone help me out? I'm ussually pretty good with PHP, but when it comes to regular expressions I'm like a fish out of water.
Basically, I want to turn the following...
Code: Select all
Hello, my name is [[David]].Code: Select all
Hello, my name is <a href="url.php?entry=David">David</a>.