Jump to content

a dumb question..(newbie)


yusof_hardy

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..?
Link to comment
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)
Link to comment
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.
Link to comment
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. 
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.