Jump to content


Photo

a dumb question..(newbie)


  • Please log in to reply
4 replies to this topic

#1 yusof_hardy

yusof_hardy
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 05 July 2006 - 03:03 PM

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


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


=============================================
When I type

a
b
c

in the text area


I get

a

b

c

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..?

#2 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 05 July 2006 - 05:07 PM

i don't remember...but i think this might be a platform problem.

are you on windows?

in any case, change this:
$file1 = fopen("text1.txt", "w");

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

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 July 2006 - 06:20 PM

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?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 Koobi

Koobi
  • Staff Alumni
  • Advanced Member
  • 419 posts
  • LocationColombo, Sri Lanka | South Asia

Posted 05 July 2006 - 06:26 PM

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?



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.

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 05 July 2006 - 07:05 PM

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?

okay yeah i see that now. windows treats a text file and binary file differently.  so yes, doing 'wb' is good idea. 

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

unfortunately adding the b still produces the double lines. 
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users