rbblue8 Posted February 4, 2008 Share Posted February 4, 2008 Hey all... i get a file via a IMAP connection, and store it in $rawmessage. i then call fwrite as follows. [code]fwrite($FILE, utf8_encode($raw_message)); fclose($FILE); $tempFileOK = TRUE; and i have tried fwrite($FILE, $raw_message); fclose($FILE); $tempFileOK = TRUE; in the file that it creates.. i get very odd characters which is causing the next phase... which reads that file.. to fail. The character that i'm getting is ^M at the end of every line. i then thought.. ok.. perhaps it's coming from the IMAP server.. well it's not.. for i then displayed all of $raw_message via [ code]echo $ram_message[/code] and i do not get the ^M sign at all. can you suggest a way to get rid of this when putting it to the file? Quote Link to comment https://forums.phpfreaks.com/topic/89432-solved-fwrite-is-giving-me-junk-in-file/ Share on other sites More sharing options...
rbblue8 Posted February 5, 2008 Author Share Posted February 5, 2008 anyone have ANY thoughts on this? Quote Link to comment https://forums.phpfreaks.com/topic/89432-solved-fwrite-is-giving-me-junk-in-file/#findComment-458690 Share on other sites More sharing options...
mr_mind Posted February 5, 2008 Share Posted February 5, 2008 have you tried file_put_contents() ? Quote Link to comment https://forums.phpfreaks.com/topic/89432-solved-fwrite-is-giving-me-junk-in-file/#findComment-458708 Share on other sites More sharing options...
rbblue8 Posted February 5, 2008 Author Share Posted February 5, 2008 if (file_put_contents($tempFile, $raw_message)) { //$FILE = @fopen($tempFile, 'w'); //fwrite($FILE, utf8_encode($raw_message)); //fclose($FILE); $tempFileOK = TRUE; // run command // //$web_dir='/web/hostouremail.com/webmail/data'; $cmd = $command . ' cat < ' .$web_dir.''.$tempFile; is still giving me the ^M at the end of every line of the file. Quote Link to comment https://forums.phpfreaks.com/topic/89432-solved-fwrite-is-giving-me-junk-in-file/#findComment-458805 Share on other sites More sharing options...
kenrbnsn Posted February 5, 2008 Share Posted February 5, 2008 The "^M" character is a carriage return. Try trimming your $raw_message and re-adding the linebreak character. <?php fwrite($FILE, trim($raw_message) . "\r\n"); fclose($FILE); $tempFileOK = TRUE; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/89432-solved-fwrite-is-giving-me-junk-in-file/#findComment-458825 Share on other sites More sharing options...
vidyadoiphode Posted February 5, 2008 Share Posted February 5, 2008 You can get answers on http://php-infosource.blogspot.com Quote Link to comment https://forums.phpfreaks.com/topic/89432-solved-fwrite-is-giving-me-junk-in-file/#findComment-458829 Share on other sites More sharing options...
rbblue8 Posted February 5, 2008 Author Share Posted February 5, 2008 fixed with this $raw_message=preg_replace("/\r\n/", "\n", $raw_message); thanks all for your help! Quote Link to comment https://forums.phpfreaks.com/topic/89432-solved-fwrite-is-giving-me-junk-in-file/#findComment-458876 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.