yusof_hardy Posted July 5, 2006 Share Posted July 5, 2006 $text = $_POST['textarea']; //data from a textarea$file1 = fopen("text1.txt", "w");$text = stripslashes($text);fwrite($file1, $text);fclose($file1);=============================================When I type[quote]abc[/quote] in the text areaI get[quote]abc[/quote]in the fileHow 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 https://forums.phpfreaks.com/topic/13740-a-dumb-questionnewbie/ Share on other sites More sharing options...
Koobi Posted July 5, 2006 Share Posted July 5, 2006 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 https://forums.phpfreaks.com/topic/13740-a-dumb-questionnewbie/#findComment-53430 Share on other sites More sharing options...
.josh Posted July 5, 2006 Share Posted July 5, 2006 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? Link to comment https://forums.phpfreaks.com/topic/13740-a-dumb-questionnewbie/#findComment-53478 Share on other sites More sharing options...
Koobi Posted July 5, 2006 Share Posted July 5, 2006 [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 https://forums.phpfreaks.com/topic/13740-a-dumb-questionnewbie/#findComment-53482 Share on other sites More sharing options...
.josh Posted July 5, 2006 Share Posted July 5, 2006 [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 https://forums.phpfreaks.com/topic/13740-a-dumb-questionnewbie/#findComment-53513 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.