Parts of string that dont HAVE to be there
Posted: Wed Apr 16, 2008 4:17 am
I was intruiged as to how to build a parse that would run like bbcode does.
So's i had a go at it, somewhat shakily and naively.
As was expected, i hit a snare: when searching for a [url=http...] i could easily turn this into a real url using
The problem was hit when i wanted to give the user the option of an extra - the 'target' attribute. I managed to get it working using this:
but obviously if the target isn't present problems will arise.
So, my question is: how can i have extra(s*) in the url that dont have to be there?
And how would i go about adding others such as: title, name, id... etc.
Kind regards!
p.s. im terrible of thinking up thread titles!
So's i had a go at it, somewhat shakily and naively.
As was expected, i hit a snare: when searching for a [url=http...] i could easily turn this into a real url using
Code: Select all
preg_replace('#\[url=(.*)\](.*)\[/url\]#', "<a href='$1'>$2</a>", $_string);
Code: Select all
preg_replace('#\[url=(.*) target=(.*)\](.*)\[/url\]#', "<a target='$2' href='$1'>$3</a>", $_string);
So, my question is: how can i have extra(s*) in the url that dont have to be there?
And how would i go about adding others such as: title, name, id... etc.
Kind regards!
p.s. im terrible of thinking up thread titles!