<?php
function dosomething($string, $else = '') {
if (empty($else))
$string = "<b>$string</b>";
else
$string = "<i>$string</i>";
return $string;
}
$input = "Some words.
[code]some code.
More words.
.
Other words.";
$codetag = array('\
[code\]', '\[quote\]');
$codetag_rev = array('\[\/code\]', '\[\/quote\]');
for ($i = 0; $i < count($codetag); $i++)
$codetag_array[] = "/([\s\S]*$codetag[$i])([\s\S]+)($codetag_rev[$i])([\s\S]*)/e";
$input_new = preg_replace($codetag_array, 'dosomething("$1") . dosomething("$2","else") .dosomething("$3") . dosomething("$4")', $input);
echo "$input\n<hr>\n$input_new";
// This becomes a huge mess and $2 doesn't get saved from being bold
echo "<hr><hr>";
// It does work fine if I only try it on one tag
$input_new = preg_replace($codetag_array[0], 'dosomething("$1") . dosomething("$2","else") .dosomething("$3") . dosomething("$4")', $input);
echo "$input\n<hr>\n$input_new";
// $2 is indeed saved from turning bold
?>
[/code]
So my only question is - how do I do this for multiple tags?
Or, if you want, you can simply ignore everything until now and just tell me how do I turn $input into:
// Output:
<b>Some words.
[code]</b><i>some code.</i>
<b>
More words.
.
Other words.</b>;
[/code]
Thanks!