oliverj777 Posted August 24, 2010 Share Posted August 24, 2010 Basically, All I want to do is save a .txt (doesn't have to be .txt) to my FTP and PHP simple echos it. The .txt is where a message is stored. But when I write the message my self like this: Hello This is a message. - And then upload it to my FTP, PHP echos it like this "HelloThis is a message". Is there anyway for PHP to notice the 'white space'? --OR-- If you know of a better way to make a message system, then also let me know Thanks, Ollie! Quote Link to comment Share on other sites More sharing options...
Adam Posted August 24, 2010 Share Posted August 24, 2010 It isn't PHP that ignores the white-space, it's the browser. If you look at the source you'll see the spacing is preserved. HTML offers the <pre> tag that by default preserves white-space, or you can apply the CSS property white-space:nowrap;. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 24, 2010 Share Posted August 24, 2010 Use the function nl2br on the data when displaying it. Ken Quote Link to comment Share on other sites More sharing options...
Adam Posted August 24, 2010 Share Posted August 24, 2010 ... or nl2br() .. However what I said is true and may come in useful in the future when line-breaks are not the problem. Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted August 24, 2010 Author Share Posted August 24, 2010 Where would I insert that then? Here is the code im using to echo: include("mail.txt"); Cheers Quote Link to comment Share on other sites More sharing options...
Adam Posted August 24, 2010 Share Posted August 24, 2010 Read the contents of the file with file_get_contents into a variable and apply nl2br() to that. Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted August 24, 2010 Author Share Posted August 24, 2010 Umm - help me out here. Is this correct: $mail = file_get_contents("users/$session->username/messages/mail.txt"); nl2br($mail); echo $mail; Quote Link to comment Share on other sites More sharing options...
Adam Posted August 24, 2010 Share Posted August 24, 2010 You need to assign the result of nl2br() to $mail: $mail = nl2br($mail); Quote Link to comment Share on other sites More sharing options...
oliverj777 Posted August 24, 2010 Author Share Posted August 24, 2010 Nice one mate - it works! Quote Link to comment 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.