PDA

View Full Version : coding help



Colin-Roberts
12-11-2006, 06:50 PM
i need help placing / modding code
ok this is the file that proccess the shout in this file i want http://thybag.co.uk/?p=Tutorials&ind=40 added so it proccesses the smileys and bad words for $message

<?php

$name = $_POST['name'];
$website = $_POST['website'];
$message = $_POST['message'];

if(empty($name) OR empty($message))
{
echo "

<script language='javascript'>

alert('You need to fill out both of the form fields...');

</script>
";

}
else
{

echo "

<script language='javascript'>

alert('Thanks for your message $name...');

</script>
";
$name = htmlspecialchars($name);
$message = htmlspecialchars($message);
$tag = ("<font size=\"1\" face=\"Verdana\">
<b>$name</b>: $message </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;/v3/shout.htm\">";

// Copyright 2006 - 2007 Colin-Roberts.net

?>

YouFail
12-11-2006, 07:09 PM
You need to make a BBCODE file. I'll explain it later.

Colin-Roberts
12-11-2006, 07:19 PM
kk thanx richard

Mentor
12-11-2006, 07:21 PM
i need help placing / modding code
ok this is the file that proccess the shout in this file i want http://thybag.co.uk/?p=Tutorials&ind=40 added so it proccesses the smileys and bad words for $message


I set it all out in functions to make it realy easy to add in, u just copy in the functions and, call em when u want em.

<?php
//Get varibles
$name = $_POST['name'];
$website = $_POST['website'];
$message = $_POST['message'];
//Define functions
function filter($msg)
{
//replace the veg with sware words.
$bad_words = explode(',', "tomato,lettuce,carrot,potato,broccoli,cucumber,pea" );
foreach ($bad_words as $naughty)
{
$msg = eregi_replace($naughty, "****", $msg);
}
return $msg;
}
function doSmily($msg)
{
$msg = str_replace(':)', '<img src="Smileys/smile.gif" alt=":)" />', $msg);
$msg = str_replace(':(', '<img src="Smileys/sad.gif" alt=":(" />', $msg);
$msg = str_replace(':D', '<img src="Smileys/biggrin.gif" alt=":D" />', $msg);
$msg = str_replace(';)', '<img src="Smileys/wink.gif" alt=";)" />', $msg);
$msg = str_replace(':o', '<img src="Smileys/ohmy.gif" alt=":o" />', $msg);

return $msg;
}

//Start the page code
if(empty($name) OR empty($message))
{
echo "

<script language='javascript'>

alert('You need to fill out both of the form fields...');

</script>
";

}
else
{

echo "

<script language='javascript'>

alert('Thanks for your message $name...');

</script>
";
//Before we add to the DB, we remove the bad words
$message = 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.
$message = doSmily(htmlspecialchars($message));

//And the rest of your code
$tag = ("<font size=\"1\" face=\"Verdana\">
<b>$name</b>: $message </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;/v3/shout.htm\">";

// Copyright 2006 - 2007 Colin-Roberts.net

?>

Colin-Roberts
12-11-2006, 07:33 PM
Parse error: syntax error, unexpected T_VARIABLE in addtag.php on line 55
(addtag.php is the file i posted)
Line 55:

$name = htmlspecialchars($name);

the lines around it:

$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.
$message = doSmily(htmlspecialchars($message));

Mentor
12-11-2006, 07:55 PM
Ah, yes a simple stupid mistake.. although i cant see how someone, who coulnt see what it was themselves after knowing about it, can actualy claime to know php...


//Before we add to the DB, we remove the bad words
$message = filter($message);

Want to hide these adverts? Register an account for free!