Colin-Roberts
02-02-2009, 10:24 PM
Ok why is this not replacing the input text (from a form) with smileys and filtering the bad words.
<?php
//Get varibles
$name = $_POST['name'];
$website = $_POST['website'];
$message = $_POST['message'];
//Define functions
function filter($message)
{
//replace the veg with sware words.
$bad_words = explode(',', "*******,****,*****,*******,ass,*******,****,****,* ****" );
foreach ($bad_words as $naughty)
{
$msg = eregi_replace($naughty, "****", $message);
}
return $msg;
}
function doSmily($message)
{
$msg = str_replace(':)', '<img src="ttp://www.colin-roberts.net/news/rte/images/smiley.gif" alt=":)" />', $msg);
$msg = str_replace(':(', '<img src="ttp://www.colin-roberts.net/news/data/emoticons/sad.gif" alt=":("', $msg);
$msg = str_replace(':D', '<img src="http://www.colin-roberts.net/news/data/emoticons/laughing.gif" alt=":D" />', $msg);
$msg = str_replace(';)', '<img src="ttp://www.colin-roberts.net/news/data/emoticons/wink.gif" alt=";)" />', $msg);
$msg = str_replace('>:(', '<img src="ttp://www.colin-roberts.net/news/data/emoticons/angry.gif" alt=">:(" />', $msg);
return $message;
}
//Start the page code
if(empty($name) OR empty($message))
{
}
else
{
echo "
<script language='javascript'>
alert('Thanks for your message $name...');
</script>
";
//Before we add to the DB, we remove the bad words
$mge = filter($message);
$name = htmlspecialchars($name);
// Note, Dosmily function is called after html charicters have been removed. This is so the image codes do not also get filtered, which would stop them from showing up correctly.
$mess = doSmily(htmlspecialchars($mge));
//And the rest of your code
$tag = ("<font size=\"1\" face=\"Verdana\">
<b>$name</b>: $mess </font><br><br>");
$read = fopen("content.txt", "r");
$contents = fread($read, filesize('content.txt'));
fclose($read);
$write = fopen("content.txt", "w");
fwrite($write, "$tag $contents");
fclose($write);
}
print "<meta http-equiv=\"refresh\" content=\"0;http://www.colin-roberts.net/shoutbox/Shoutbox.htm\">";
// Copyright 2006 - 2007 Colin-Roberts.net
?>
<?php
//Get varibles
$name = $_POST['name'];
$website = $_POST['website'];
$message = $_POST['message'];
//Define functions
function filter($message)
{
//replace the veg with sware words.
$bad_words = explode(',', "*******,****,*****,*******,ass,*******,****,****,* ****" );
foreach ($bad_words as $naughty)
{
$msg = eregi_replace($naughty, "****", $message);
}
return $msg;
}
function doSmily($message)
{
$msg = str_replace(':)', '<img src="ttp://www.colin-roberts.net/news/rte/images/smiley.gif" alt=":)" />', $msg);
$msg = str_replace(':(', '<img src="ttp://www.colin-roberts.net/news/data/emoticons/sad.gif" alt=":("', $msg);
$msg = str_replace(':D', '<img src="http://www.colin-roberts.net/news/data/emoticons/laughing.gif" alt=":D" />', $msg);
$msg = str_replace(';)', '<img src="ttp://www.colin-roberts.net/news/data/emoticons/wink.gif" alt=";)" />', $msg);
$msg = str_replace('>:(', '<img src="ttp://www.colin-roberts.net/news/data/emoticons/angry.gif" alt=">:(" />', $msg);
return $message;
}
//Start the page code
if(empty($name) OR empty($message))
{
}
else
{
echo "
<script language='javascript'>
alert('Thanks for your message $name...');
</script>
";
//Before we add to the DB, we remove the bad words
$mge = filter($message);
$name = htmlspecialchars($name);
// Note, Dosmily function is called after html charicters have been removed. This is so the image codes do not also get filtered, which would stop them from showing up correctly.
$mess = doSmily(htmlspecialchars($mge));
//And the rest of your code
$tag = ("<font size=\"1\" face=\"Verdana\">
<b>$name</b>: $mess </font><br><br>");
$read = fopen("content.txt", "r");
$contents = fread($read, filesize('content.txt'));
fclose($read);
$write = fopen("content.txt", "w");
fwrite($write, "$tag $contents");
fclose($write);
}
print "<meta http-equiv=\"refresh\" content=\"0;http://www.colin-roberts.net/shoutbox/Shoutbox.htm\">";
// Copyright 2006 - 2007 Colin-Roberts.net
?>