Jump to content

[SOLVED] noob missing returns in code


ski.c0411

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.