Results 1 to 5 of 5
I am using fputs to print some lines to a file but It doesn't include the end of line
character at the end of the string so the strings are ...
- 04-06-2011 #1
can someone help me with php file i/o
I am using fputs to print some lines to a file but It doesn't include the end of line
character at the end of the string so the strings are all written to the top line.
how can I add eol to the end of a string printed to a file.
also how can I read each line of a file by using eol to end the string I want read.
- 04-06-2011 #2
fputs() simply prints the string to the file. If the string does not have a newline in it, no newline will be written to the file. So there are two solutions:
1) Add a newline to the end of the string that you are printing
2) Explicitly print a newline to the file after the string:
Reading a line from a file is done by using the fgets() function:Code:fputs($fp, "\n");
PHP: fgets - ManualDISTRO=Arch
Registered Linux User #388732
- 04-06-2011 #3
PHP: stream_get_line - Manual
PHP: fgets - Manual
Can you please post the code?
- 04-06-2011 #4If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.
- 04-06-2011 #5
Heres a copy of the code
While you guys are here is there a more resourceful way too use the fputs that is already being used?
I was wondering if I could do
Code:fputs($handle, $_POST["username"]."\n");
Heres a copy of the code
Code:<?php session_start(); if ($_SESSION['id_num'] <= 0) { $_SESSION['id_num'] = rand(); } if (!$_POST["username"]) { echo "<p style=\"color:red;font-weight:bold;margin-left:95px\">"; echo "* A username is required</p>"; include("account creation.html");exit; } else { /* $username = $_POST["username"]; $password = $_POST["password"]; $passwordvar = $_POST["passwordvar"]; $firstname = $_POST["firstname"]; $middlename = $_POST["middlename"]; $lastname = $_POST["lastname"]; $streetaddress = $_POST["streetaddress"]; $aptnumber = $_POST["aptnumber"]; $streetaddresstwo = $_POST["streetaddresstwo"]; $city = $_POST["city"]; $state = $_POST["state"]; $zipcode = $_POST["zipcode"]; */ if ($_POST["password"] != $_POST["passwordvar"]) { echo "<p style=\"color:red;font-weight:bold;margin-left;95px\">"; echo "Password's are not the same</p>"; include("account creation.html");exit; } else { $syslog = fopen(",/system", "a"); if(file_exists("database/".$_POST["username"])) { echo "<p style=\"color:red;font-weight:bold;margin-left:95px\">"; echo "The username you entered already exists</p>"; include("account creation.html");exit; } else { if (!$handle = fopen("database/".$_POST["username"], "w+")) { fputs($syslog, "Unable to open database/".$_POST["username"]); echo "<p style=\"color:red;font-weight:bold;margin-left;95px\">"; echo "Password's are not the same</p>";exit; } else { if($_POST["username"]){fputs($handle, $_POST["username"]);} if($_POST["password"]){fputs($handle, $_POST["password"]);} if($_POST["passwordvar"]){fputs($handle, $_POST["passwordvar"]);} if($_POST["firstname"]){fputs($handle, $_POST["middlename"]);} if($_POST["middlename"]){fputs($handle, $_POST["middlename"]);} if($_POST["lastname"]){fputs($handle, $_POST["lastname"]);} if($_POST["streetaddress"]){fputs($handle, $_POST["streetaddress"]);} if($_POST["aptnumber"]){fputs($handle, $_POST["aptnumber"]);} if($_POST["streetaddresstwo"]){fputs($handle, $_POST["streetaddresstwo"]);} if($_POST["city"]){fputs($handle, $_POST["city"]);} if($_POST["state"]){fputs($handle, $_POST["state"]);} if($_POST["zipcode"]){fputs($handle, $_POST["zipcode"]);} fclose($handle); } } fclose($syslog); include("redirect.php"); echo "<p style=\"color:red;font-weight:bold;margin-left;95px\">"; echo "No data has been saved...<br><br>"; echo " I am currently working on this form, try back<br>"; echo "tommarrow or the day after and check on my<br>"; echo "progress.<br>"; echo "and or email me: eric_justin_allan@cfl.rr.com</p>"; } } ?>


Reply With Quote
