I have a variation on this that replaces the text with a button that pops up the "hidden" text when clicked. example on the Math Is Fun forum
This is so that people can solve math puzzles without giving the answer away to other puzzlers, yet their solution is still easy to find.
In parser.php I added:
function handle_hide_tag($text, $button = 'Show Hidden Text')
{
global $pun_user;
$s = '<span><form name="hide" method="post" action="message.php" style="display: inline;"><input type="hidden" name="msg" value="'.$text.'" style="border: 0; padding: 0;"><input type="submit" name="Submit" value="'.$button.'"></form></span>';
return $s;
}
And also in parser.php I made the hide tag call up the handle_hide_tag function (like the url tag calls handle_url_tag), and ended up with this result in function do_bbcode():
$pattern = array('#\[b\](.*?)\[/b\]#s',
'#\[i\](.*?)\[/i\]#s',
'#\[u\](.*?)\[/u\]#s',
'#\[url\](.*?)\[/url\]#e',
'#\[url=(.*?)\](.*?)\[/url\]#e',
'#\[email\](.*?)\[/email\]#',
'#\[email=(.*?)\](.*?)\[/email\]#',
'#\[hide\](.*?)\[/hide\]#e',
'#\[hide=(.*?)\](.*?)\[/hide\]#e',
'#\[color=([a-zA-Z]*|\#?[0-9a-fA-F]{6})](.*?)\[/color\]#s');
$replace = array('<strong>$1</strong>',
'<em>$1</em>',
'<span class="bbu">$1</span>',
'handle_url_tag(\'$1\')',
'handle_url_tag(\'$1\', \'$2\')',
'<a href="mailto:$1">$1</a>',
'<a href="mailto:$1">$2</a>',
'handle_hide_tag(\'$1\')',
'handle_hide_tag(\'$2\', \'$1\')',
'<span style="color: $1">$2</span>');
I then created a simple page "message.php" that simply displays the text neatly.
I know this is not a very good description of the changes, but hopefully there are enough clues here for anyone else to create this functionality