$str = preg_replace("/\[b\](.*?)\[\/b\]/is", "<strong>$1</strong>", $str);
For bold text.
Now i understand pretty much all of it, " (.*?) " is essentially a wildcard, meaning "anything", but is there a way of limiting what it is in there?
for example, when working with size tags, e.g.
[size=x][/size]
where x should be numeric, and if possible, between 2 pre-defined numbers.
Now i know i could go through each possible outcome, but can this been done via preg_replace (or some other similar function) ?
EDIT: Figuerd out how to limit to numbers:
$str = preg_replace("/\[size\=\"([0-9]*?)\"\](.*?)\[\/size\]/is", "<span style="font-size:$1px;">$2</span>", $str);
Still not sure on the limiting the numbers that can be entered though
EDIT2: After finding this very useful forum entry listing all the pattern symbols, i've figured it out. For those interested, here it is:
$str = preg_replace("/\[size\=\"([0-5]?[0-9]?)\"\](.*?)\[\/size\]/is", "<span style="font-size:$1px;">$2</span>", $str);
However this does allow people to use size 0, i.e. invisible... but what do i care? you gotta be a tard to use that
EDIT3: Again for any who are interested, i finally got it completely working (I Hope)
$str = preg_replace("/\[size\=\"([1-5][0-9]{1}|[8-9]{1})\"\](.*?)\[\/size\]/is", "<span style="font-size:$1px;">$2</span>", $str);
This limits the user to only using sizes between(and including) 8-50
Edited by Bob, 10 February 2008 - 17:33.