Never mind everyone, I figured it out.  In this line:

$data_line = implode($separator, $data_array)."\n";

I was adding a newline when I didn't need too.

Jason

On Sat, 2003-07-12 at 17:03, Jason Giangrande wrote:
> I have written this function to rewrite the contents of a text file
> after it's been updated.  I store lines of data in an array and then
> implode them into one string.  The problem is that I'm getting an extra
> line break (in other words a blank line is showing up in my text file)
> after I modify a particular line.  I checked the imploded string with
> var_dump and don't see any line breaks besides the ones that separate
> each line.  Anyone have any ideas as to why I'm getting an extra line
> break?  The function is below with the code that calls it below that.
> 
> Jason
> 
> // Rewrite data file from array of file lines
> function rewrite_file($lines) {
>       $filecontents = implode("\n", $lines);
>       $fh = fopen("data.txt", "w") or die("Could not open file.");
>       flock($fh, LOCK_EX);
>       if (fwrite($fh, $filecontents) == -1) {
>               die("File could not be written to.");
>       }
>       ftruncate($fh, ftell($fh)) or die("Error.");
>       flock($fh, LOCK_UN);
>       fclose($fh) or die("Error.");
> }
> 
> <-###########################################################->
> 
> $uid = $_POST['id'];
> $title = stripslashes(strip_tags(trim($_POST['title'])));
> $name = array_search($username, $full_name);
> $email = array_search($username, $user_email);
> $date = $_POST['date'];
> $category = $_POST['category'];
> $article = stripslashes(trim($_POST['article']));
> 
> $data_array = array($uid, $title, $name, $email, $date, $category,
> $article);
> $data_line = implode($separator, $data_array)."\n";
> 
> $filelines = return_lines(); // Reads file and returns array of it's
> lines.
> for ($i = 0; $i <= count($filelines); $i++) { // loop through array in
> order
>   if (strstr($filelines[$i], $uid) != FALSE) {
>     $data_pos = array_search($filelines[$i], $filelines);
>     array_splice($filelines, $data_pos, 1, $data_line);
>   }
> }
> rewrite_file($filelines);
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to