View Full Version : Line feed in saved file


jocelyn
08-12-2005, 05:05 PM
Started to look at php. Did a page to submit name, email... to a file.
Works but all the data is apended one after the other like this

name1email1...name2email2...

Tried a lot of stuff and read a lot of things like the ascii chr(13)... so the file would look like this

name1
email1
...
name2
email2
...

Must be an easy one but I'm wasting lots of time reading loads of sites for nothing. Someone know how to make a carriage return in a file ...

dilligaf
08-12-2005, 06:05 PM
I don't do php but I'd guess the concept would be the same. It looks like you're getting data via email as opposed to writing to a db and retreiving it. If so, it seems as it would be a function of how you're processing the email more so than what's submitted.

In ASP/Windows you have ASPEmail, ASPmail, CDONTS, CDOSYS... now if you're writing to a db it's all the same (SQL Server, Access).

Sorry, I've only done prepackaged in php/mysql so I might be missing it completely.

jocelyn
08-12-2005, 07:33 PM
Making an append on a txt file on the server. I don't do dbase stuff yet, I'm a one day old php newbie... lol

Paz
08-12-2005, 10:35 PM
Hi,

I'm sure a php expert will be along shortly to help!

Love the chef's avatar by the way.... I see you have a "white hat" of course... ;)

Cheers,
Paz.

jocelyn
08-13-2005, 06:13 AM
That is what I used...

<?
$filehandle = fopen("data.txt", "a");
fputs($filehandle, "$name");
fputs($filehandle, "$email");
fputs($filehandle, "$url");
fclose($filehandle);
print("Successfully added <b>$url</b> to the review queue");
?>

Tried using these too :

fputs($filehandle, "$name".chr(10));
fputs($filehandle, "$name".chr(13));

Atomical
08-14-2005, 08:22 AM
The correct way to do this is as follows:
fputs($filehandle, "$name\n");

You can also use fwrite for the same thing. When I think of fputs() I think of sockets.

You guys are noobs :)

dilligaf
08-14-2005, 08:38 AM
[QUOTE=Atomical]
You guys are noobs :)[/QUOTE]TFF!

jocelyn
08-15-2005, 01:14 PM
[QUOTE=Atomical]You guys are noobs :)[/QUOTE]
What's a noobs... a newbie... well yeah, got about 4-5 hours reading on the php basics and made the big code I posted above... mr dilli is not a php but an asp artist... at least he tried to help.

I think I tried the code you gave and it only gave a nice little squarebox like the chr$(13) one, all on the same line still... but maybe I did something wrong and will try it again.

Thanks for the help buddy !

Atomical
08-15-2005, 04:16 PM
Why don't you post your new code. Linux line endings aren't the same as Mac and Windows. What platform are you running this on?

jocelyn
08-15-2005, 04:37 PM
It's on a linux server.

I used this whole big php script... kind of like the top one... lol

<?
$filehandle = fopen("data.txt", "a");
fputs($filehandle, "$name\n");
fputs($filehandle, "$email\n");
fputs($filehandle, "$url\n");
fclose($filehandle);
print("Successfully added <b>$url</b> to the review queue");
?>

And it gave the same thing....

moi
page@dada.comhttp://www.bothunter.com

Note: you see two lines because the little square turned in what it is... a carriage return, but the forum, unlike notepad and other text editors, decided to use it as a return instead of showing the little square.

This sounds like fun stuff... it takes me days to get multiple lines to be saved in a file... how would it be if I intended to do the whole data manipulation on php... if I can just get this to do that, or at least one line per submission, I'll do the rest with VB.

jocelyn
08-15-2005, 04:42 PM
Oh yeah forgot to say... did the fwrite and it does the same thing but more consistent... I get a square after all the entries, unlike the example I put above... one step further.

Atomical
08-15-2005, 06:37 PM
Your problem is this. Linux and Windows both have different ways to indicate the end of a line. View your log file through your web browser.

jocelyn
08-15-2005, 07:31 PM
I would have looked a long time for a bug that was not a bug. It's appreciated and I thank you.