Jump to content

Archived

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

yusof_hardy

a dumb question..(newbie)

Recommended Posts

$text = $_POST['textarea'];      //data from a textarea


$file1 = fopen("text1.txt", "w");
$text = stripslashes($text);
fwrite($file1, $text);
fclose($file1);


=============================================
When I type
[quote]
a
b
c
[/quote] in the text area


I get
[quote]
a

b

c
[/quote]in the file



How can I fix this?


And can some one please give me some bright knowlege on stripslashes and all those magic quotes things..?

Share this post


Link to post
Share on other sites
i don't remember...but i think this might be a platform problem.

are you on windows?

in any case, change this:
[code=php:0]
$file1 = fopen("text1.txt", "w");
[/code]

to this:
[code=php:0]
$file1 = fopen("text1.txt", "wb");
[/code]
to make it binary safe (it's in the manual on the page about fopen if you want to read more about it)

Share this post


Link to post
Share on other sites
replace this:
$text = stripslashes($text);

with this:

$text = stripslashes(str_replace("\r\n", "\n", $text));

koobie i thought fopen and fwrite were already binary safe by default?

Share this post


Link to post
Share on other sites
[quote author=Crayon Violent link=topic=99525.msg392088#msg392088 date=1152123609]
replace this:
$text = stripslashes($text);

with this:

$text = stripslashes(str_replace("\r\n", "\n", $text));

koobie i thought fopen and fwrite were already binary safe by default?
[/quote]


not on win bases as far as i know. unfortunately i can't test that out for myself at home. would you be able to verify that for me if it's not too much trouble for you?

adding the "b" to the mode parameter should do the replacing itself without the need for str_replace() if i'm not mistaken.

Share this post


Link to post
Share on other sites
[quote author=Koobi link=topic=99525.msg392093#msg392093 date=1152123974]
not on win bases as far as i know. unfortunately i can't test that out for myself at home. would you be able to verify that for me if it's not too much trouble for you?
[/quote]
okay yeah i see that now. windows treats a text file and binary file differently.  so yes, doing 'wb' is good idea. 

[quote]
adding the "b" to the mode parameter should do the replacing itself without the need for str_replace() if i'm not mistaken.
[/quote]
unfortunately adding the b still produces the double lines. 

Share this post


Link to post
Share on other sites

×

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.