Jump to content

PHP HELP


driz
 Share

Recommended Posts

You have blank lines in the text file that the PHP script thinks are a separate post. You split up the text file into lines and then treat each line as a post. Either remove the blank lines in the text file or change the script to check if the line is blank before it prints a post.

Link to comment
Share on other sites

Instead of this:if(!empty($line))Do this:if (trim($line) != "")Deleting isn't very easy with a text file-based system, at least compared to a database. You'll need to print delete links with a counter where you count each post. So you will need a counter variable that gets incremented whenever you print a post that you can attach to a delete link, something like this:<a href="index.php?mode=delete&post=<?php echo $counter; ?>">delete</a>The PHP script will need to check the $_GET['mode'] variable to see if it equals "delete", get the $_GET['post'] variable to see which post to delete, and then count through the file until you find that post. If you use the file function to read the file into an array, you can just delete that array element and write the array back to the file, or something like that.

Link to comment
Share on other sites

You could even just flip between true and false for a variable:

$nr = true;while (...) {  if ($nr) {	// choice 1  } else {	// choice 2  }	  $nr = !$nr;}

This may be slightly faster than incrementing the variable.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...