EZE
03-02-2007, 11:33 PM
I've been trying to make a bbcode parser for canceling out html and bbcode in between 2 [cancel] tags, so users can input bbcode and such without it disappearing and parsing when they don't want it too. For example, [b]yo]/b] would so up as [b]yo]/b] in plain text. I have this code and it the only thing that doesn't work is the cancel tags:
<?php
$send = $_POST['send'];
$text = $_POST['text'];
if(!$send){
echo '<form action="" method="post"><textarea name="text"/></textarea><input type="submit" name="send"/></form>';
}
elseif($send){
function cancel($var){
if(preg_match('/\[cancel\](.*?)\[\/cancel\]/is',$var,$matches)){
$var = preg_replace('/\[cancel\](.*?)\[\/cancel\]/is',htmlentities('$1'),$var);
$var = str_replace(array("[", "]"), array("[", "]"), $matches[1]);
}
return $var;
}
cancel($text);
$text = preg_replace('/\[b\](.*?)\[\/b\]/is','<b>$1</b>',$text);
echo $text;
}
?> Anybody know whats wrong? I just learned the preg_match function today, so I may have done something wrong there...:confused: :confused: :confused:(Note: the brackets in the str replace should be html replacements.)
<?php
$send = $_POST['send'];
$text = $_POST['text'];
if(!$send){
echo '<form action="" method="post"><textarea name="text"/></textarea><input type="submit" name="send"/></form>';
}
elseif($send){
function cancel($var){
if(preg_match('/\[cancel\](.*?)\[\/cancel\]/is',$var,$matches)){
$var = preg_replace('/\[cancel\](.*?)\[\/cancel\]/is',htmlentities('$1'),$var);
$var = str_replace(array("[", "]"), array("[", "]"), $matches[1]);
}
return $var;
}
cancel($text);
$text = preg_replace('/\[b\](.*?)\[\/b\]/is','<b>$1</b>',$text);
echo $text;
}
?> Anybody know whats wrong? I just learned the preg_match function today, so I may have done something wrong there...:confused: :confused: :confused:(Note: the brackets in the str replace should be html replacements.)