Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-21-2008, 10:07 PM   PM User | #1
MindTheGap
New Coder

 
Join Date: Jul 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
MindTheGap is an unknown quantity at this point
Page Layout Help

First: here is my script:
PHP Code:
<?php
// Configuration (change these if you want)
$filename "shouts.txt";    // The file to store shouts in
$date "jS M, g:i A";        // Date format for shouts (see http://php.net/date)
$timemod 0;            // Time modifier, in hours, use this to adjust the time
$amount 0;            // Amount of shouts to show (0 = all)


$shouthtml = <<<HTML
{date}
<br />
{message}
<p />
HTML;

$html = <<<HTML
{shouts}
<form method="post">
{errors}
<p />
Message: <input type="text" name="message" />
<p />
<input type="submit" name="submit" value="Shout" />
</form>
<p />

HTML;

// Code

if (!file_exists($filename))
{
    
// File does not exist, create it
    
$f = @fopen($filename"w") or die("Cannot access $filename, wrong permissions maybe?");
    
fclose($f);
}

if (isset(
$_POST['submit']))
{
    
// User has clicked the "Shout" button
    
    // Make safe all posted data, also store other data
    
if (get_magic_quotes_gpc())
    {
        
$postmessage trim(stripslashes(htmlspecialchars($_POST['message'])));
    }
    else
    {
        
$postmessage trim(htmlspecialchars($_POST['message']));
    }
    
$postdate time();
    
    if (
$postmessage == "")
    {
        
$error .= "<span style=\"color: #FF0000;\">Please enter a message.</span> <br />";
    }
    
    if (isset(
$error))
    {
        
// An error has occurred
        // Format "error" part of HTML
        
$html str_replace("{errors}"$error "<p />"$html);
    }
    else
    {
        
// No errors :)
        // Add the shout
        
$f fopen($filename"a");
        
fwrite($f"[Date] $postdate\n[Msg] $postmessage\n");
        
fclose($f);
        
header("Location: " $_SERVER['PHP_SELF']);
        die();
    }
}

// Below: Handle all "shout" formatting

$i 0;
$f file($filename);
foreach (
$f as $val)
{
    
// Loop through every line in $filename
    
if (preg_match("/\[Date\] [^A-Za-z ][0-9].*/"$val))
    {
        
// Date line
        
$shout[$i]['date'] = str_replace("[Date]"""$val);
    }
    if (
preg_match("/\[Msg\] .*/"$val))
    {
        
// Message line
        
$shout[$i]['message'] = str_replace("[Msg]"""$val);
        
$i++;
    }
}

// Have shouts going from the top-down
$i 0;
$shout = @array_reverse($shout);

if (isset(
$shout))
{
    
// If shouts exist
    
foreach ($shout as $val => $key)
    {
        
// Limit shouts according to $amount
        
if ($i == $amount && $i != 0)
        {
        }
        else
        {
            
// Create shout HTML
            
$timeadd = (3600 $timemod);
            
$moddate date($date$key['date'] + $timeadd); // Add time modifier to date

            
$temphtml str_replace("{date}"$moddate$shouthtml);
            
$temphtml str_replace("{message}"$key['message'], $temphtml);
            
$allshouts .= $temphtml;
            
$i++;
        }
    }
}

// Below: Handle all formatting

// Format HTML to be outputted
$html str_replace("{shouts}"$allshouts$html);
$html str_replace("{errors}"""$html);
echo 
$html;

?>
I need to change it so that the message entering form always stays at the top. Any idea how to do this? Thanks.
MindTheGap is offline   Reply With Quote
Old 02-21-2008, 10:09 PM   PM User | #2
MindTheGap
New Coder

 
Join Date: Jul 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
MindTheGap is an unknown quantity at this point
Or, if possible make it so that after 50 shouts it creates a new page. (like facebook, or myspace)
MindTheGap is offline   Reply With Quote
Old 02-21-2008, 10:13 PM   PM User | #3
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
Why not just hard code the form into the html? As to the new page creation you are looking for pagination. There are many scripts available many of them for free on the net.
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:54 AM.


Advertisement
Log in to turn off these ads.