DAC Coding and Syntax Highlighting
July 23rd, 2009
No comments
Quick update to say I added a Syntax-Highlighting plugin to the Blog to aid your reading of my code.
In other news however, me and n00berific have made a fair bit of headway with DAC as of late, we’ve got all the HTML entities working while managing to strip out a few server-side functions in the process, I’m looking into optimising filesize by CSS-based newline handling, but more on that later.
For the mean time, here is DAC’s sendmessage.php for you to take a look through.
EDIT: Updated the code snippet slightly
< ?php
if (!empty($_POST["message"]) && !empty($_POST["username"]))
{
date_default_timezone_set("Europe/London");
if (stripos($_POST["message"], "/me") !== false)
$msg = "<span class='name'>" . strftime("[%H:%M] ") . htmlentities($_POST["username"]) . ": " . htmlentities(str_ireplace("/me", NULL, $_POST["message"])) . "\r\n";
else
$msg = "<span class='name'>" . strftime("[%H:%M] ") . htmlentities($_POST["username"]) . ":</span> " . htmlentities($_POST["message"]) . "\r\n";
$chat = file("chat.txt");
if (count($chat) >= 100)
{
$chat = array_slice($chat, 1, NULL, true);
file_put_contents("chat.txt", implode($chat) . $msg);
}
else
file_put_contents("chat.txt", $msg, FILE_APPEND);
echo implode($chat) . $msg;
}
else
echo file_get_contents("chat.txt");
?>