ski.c0411 Posted August 16, 2007 Share Posted August 16, 2007 Anyone understand this? I'm look at some php code that used to work but when I downloaded it, its missing all the end of line returns. I tried viewing the source a number of different ways but all the code always ends up being one long continuous line. Any help would be greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/65267-solved-noob-missing-returns-in-code/ Share on other sites More sharing options...
wildteen88 Posted August 16, 2007 Share Posted August 16, 2007 If you mean when you echo something all output its all one line when you view source. This is becuase PHP does not place end of line characters automatically after echo or print statement. PHP will only return what is actually defined between the the quotes. In order for your code to output newlines you will need to use \n in your echo statement eg: echo "line1\n"; echo "line2\n"; The result when your view the source code from the browser it'll be like this: line1 line2 Note: whitespace characters, such as: \n, \r, \t etc. Will only work within double quotes and not single quotes. If you use single quotes PHP will treat the whitespace characters as text Quote Link to comment https://forums.phpfreaks.com/topic/65267-solved-noob-missing-returns-in-code/#findComment-325933 Share on other sites More sharing options...
lemmin Posted August 16, 2007 Share Posted August 16, 2007 I think he means that he downloaded a file and somewhere in the process the end line characters have gone missing. There isn't really anyway to get them back aside from writing some code. If you look at where the line should end, usually a box shaped character will be there. You can make some simple code that replaces all occurances of this character with "\n" and it should work; however, sometimes more than just the endline characters get translated to the same "box" character and you have end lines where you don't want them. Other than that, if you don't want to go through and press enter by hand, I don't know of anything else. Quote Link to comment https://forums.phpfreaks.com/topic/65267-solved-noob-missing-returns-in-code/#findComment-325937 Share on other sites More sharing options...
ski.c0411 Posted August 16, 2007 Author Share Posted August 16, 2007 Thats correct the carriage returns in the source code are missing. However there doesn't appear to be any black boxes. I tried changing the encoding within the page properties but that hasn't worked either. I guess my only option would be to put them in by hand... Quote Link to comment https://forums.phpfreaks.com/topic/65267-solved-noob-missing-returns-in-code/#findComment-325945 Share on other sites More sharing options...
lemmin Posted August 16, 2007 Share Posted August 16, 2007 You could search for semicolons and put line breaks after all of them. It wouldn't get all of the original new lines, but would make it a little bit more easy to read. Quote Link to comment https://forums.phpfreaks.com/topic/65267-solved-noob-missing-returns-in-code/#findComment-325948 Share on other sites More sharing options...
ski.c0411 Posted August 16, 2007 Author Share Posted August 16, 2007 Not exactly what I wanted to hear but thank you for you help regardless - I really appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/65267-solved-noob-missing-returns-in-code/#findComment-325971 Share on other sites More sharing options...
ski.c0411 Posted August 16, 2007 Author Share Posted August 16, 2007 Follow up for the benefit of anyone else who might encounter this problem. Problem: Pages I downloaded were posted by someone using Unix.(maybe? not too sure) When I used Cute FTP to download the files, Cute didn't recognize the encode type and copied them over as ASCII - wiping away the carriage returns. Did that stop me? Why heck no! I edited the little piece of code I needed to (changing a url from absolute to relative: easy enough) and figured the lack of carriage returns was normal. I then uploaded and overwrote the original files. Therein loudly declaring my citizenship to noob-ville. OK, so now I'm screwed. I have a lot of code that is a complete mess. No matter how hard I tried there was no easily way to get those carriage returns back in without doing it by hand. A black pit has now developed in place of my stomach. Then I lucked out - BIG TIME. I remembered I had access to an old employees hard drive. Sure enough I found backups that did have the carriage returns. These showed up as little black boxes. I did my changes and this time I uploaded the files as BINARY. And thats the key - If I ever download something thats missing carriage returns, I'll remember to set the transfer type to BINARY. Quote Link to comment https://forums.phpfreaks.com/topic/65267-solved-noob-missing-returns-in-code/#findComment-326178 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.