Hi
I\'m making a forum, and I want people to be able to format the text in some ways.
For example, if the user write the code
{b:TEXT}
The text will be bold, or if the user write the codes {b:{i:{u:TEXT}}}
The text will be bold,italic and underline.
This works pretty fine, as long as the code stays on one line. (I do like this: preg_replace(\"/\{bπ.*?)\}/si\", \"<b>\\1</b>\", $text)π
My really problem is when it the user types the code in more than one line.
For example
{code:
if($var == 1)
{
print(\"something\");
}
}
Will output the text between <pre> and </pre> by using
$text = preg_replace(\"/\{codeπ.*?)\}$/si\", \"<pre>\\1</pre>\", $text);
The problem here is that is will take the text between \"{code:\" and the last \"}\" it finds. This works fine as long as you dont use any of those codes below the {code:-code.
For example
{code:
if($var == 1)
{
print(\"something\");
}
}
{b:more text}
will not work.
The question is, how can I do so the preg_replace uses the right end-tag ( the } )
instead of the last one?
I hope you see what I am trying to do with this. And are able to help me.
Here is how my code looks like
function parse_text($text)
{
$text = preg_replace(\"/\{bπ.?)\}/si\", \"<b>\\1</b>\", $text);
$text = preg_replace(\"/\{uπ.?)\}/si\", \"<u>\\1</u>\", $text);
$text = preg_replace(\"/\{iπ.?)\}/si\", \"<i>\\1</i>\", $text);
$text = preg_replace(\"/\{codeπ.?)\}$/si\", \"<pre>\\1</pre>\", $text);
return $text;
}
Maybe I should add that I am a newbie to regular expressions, but I have read the manual and some articles on this subject, but that has not helped me a lot.
/Staffan Olin