Jump to content

why it creates several entries


newbe123

Recommended Posts

the problem is that when I add an item to be displayed in the blog, shows three instead, which two are empty.

It should not create three entries when I just add one entry. How can I fix this?

 

<?PHP
/* define the blog content file name */
$filename = "myBlogContent.txt";
?>

 

 


<?php
/* check to see if the file exists */
if (!file_exists($filename)) {

echo "The Blog Is Empty";

}else{	

/* get the file lines into an array */

$BlogArray = file($filename);

/* count the number of blog entries */	
$count = count($BlogArray);

$i=0;

while($i<$count) {	

$new_array = explode("|", $BlogArray[$i]);

echo "Posted by: " . $new_array[1] . "<br>";

echo "Posted on: " .  date("m/d/y h:iA", time($new_array[0])) . "<br>"
echo 	

"Title: " . $new_array[2] . "<br>";


echo $new_array[3] . "<hr>";


$i ++;


}
}
?>

 

 

 

 

<?PHP
/* obtain the form data */
$who = $_POST['who'];
$title = $_POST['title'];
$content = $_POST['content'];
$content = str_replace(array("\r\n", "\r", "\n"), "<br>", $content); 

/* create timestamp variable for current date and time */
$when_ts = time(); 

/* define the blog content file name */
$filename = "myBlogContent.txt";

/* prepare the variables for adding to the file */

$new_line_content = $when_ts . "|" . $who . "|" . $title . "|" . $content . "\n";

/* open the file in the APPEND MODE */
$fh = fopen($filename, 'a+') or die("can't open file");

/* add the new content */
fwrite($fh, $new_line_content); 

/* close the file */
fclose($fh); 


//exit; // Closes further script execution . 
?>

Link to comment
https://forums.phpfreaks.com/topic/220261-why-it-creates-several-entries/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.