Notepad++ put all my PHP into one line - php

I edited a bunch of PHP files (with N++) on Computer A, uploaded it to a server, downloaded it to computer B (with N++), and they lost all their line breaks. I've done this routine many times and never had this problem.
I've tried
EOL Conversion
Opening in different text editors
Search/replaces
Everything I found on Google/SO

Open up the file in Notepad++, choose Edit -> EOL Conversion -> Windows. I kept having this problem and somehow it had been set to Mac. Transferring in binary mode worked, but it was a hack. This is better.

There seems to be a question missing?
If you want to format it, you might just want to let a code-editor that knows indentation (auto-formatting) fix it for you. Eclipse can, I'm sure netbeans can too.
I think eclipse auto-formats everything you paste automagically, but otherwise just find the formatting commands ;)

Related

PHP Netbeans coding style configuration, where is it?

I want to standardize coding style accross all the developers computers in my office, I want to export my netbeans configuration and ask the other programmers to import it on their IDEs, do you know where that config file is?
I'm using netbeans 8.02 but if you have found it on another version I can use that information to figure it out. Thanks.
you can export your preferences via Tools|Options and use the "Export..." button on the bottom left corner. Check the "Formatting" checkboxe(s) to export formatting preferences only.
It will export your settings to a ZIP file.
To import these settings on other computers, simply go to Tools|Options and use the "Import..." button ;)
I've come to the conclusion that some settings are stored in hyperspace. So while that makes your efforts (to pass settings files around) futile, on the bright side it does mean interstellar travel is one step closer!
My experimental proof is to use this from inside the ~/.netbeans/ folder:
find . -mtime 1
I then altered some settings, closed netbeans, ran the above command again, and looked for which files changed. Nothing plausible seemed to, and the implausible ones did not contain anything that looked like my changes. I also ran the same test on the Project's nbproject folder (nothing had changed), and also had a poke around inside /etc/ (there seem to be no NetBeans files there). Yet, when I restart NetBeans, and go and look at the Options again (Editor | Formatting | PHP, then "Blank Lines" was where I did my test changes), my changes are still there.
So it is either Hyperspace, or Magic. And being a scientist I am not allowed to believe in magic. QED.

PHP file losing formatting after FTP upload

I am using WinSCP to transfer files to an FTP site. I have a situation currently where one specific file within a folder loses all of its formatting when it is uploaded causing the PHP file to no longer work.
All other PHP files within the folder work correctly when uploaded.
I can't understand why just one file could be affected in this way. Can anyone shed any light on the situation?
The file was probably transferd via ASCII mode which will modify the encoding and the line endings of the file.
As you have not stated what exactly do you mean by "losing formatting", it's difficult to answer, anyway:
As per src's answer, if the line endings change due to ASCII/text mode transfers, the resulting converted file can be perceived as if it lost formatting, if opened in an editor that does not support the target line endings. Though that hardly explains why there's only one affected file. Although can WinSCP technically choose a different transfer mode for example based on a file size or modification timestamp, if configured so, I doubt you did. Also note that WinSCP defaults to binary transfer mode. It would help if you state what transfer mode do you actually use with WinSCP. Definitive source for this information is WinSCP session log file. Also sharing relevant part of a log file would also help with investigation.
Another possibility is that the affected source file was created with a different line endings in the first place (like in a different editor than you use usually). As such the problem would have nothing to do with transfer mode, or WinSCP. And the difference is possibly revealed only after you open the files using a third editor on the remote side that supports only one of the line ending formats.
Though in both of these cases, the file should still work in PHP, as PHP supports both Unix and Windows line endings. Possibly the source file has such a strange format that during ASCII/text mode transfer, the server got confused and converted the file incorrectly. But that's just a wild guess.
Again, we need more information to help you.

php searching question

I have a lot of php code and I'm going through it right now (500+ files). I was hoping to find a program that would let me easily search through the files to see which files contain a specific variable I am editing. Kind of like a super edit -> find from notepad++. Anyone have any suggestions?
Best,
Pavan
One word. ack.
You can also try Agent Ransack
You can use a PHP ide such as NetBeans or your alternative is if you want to stick with notepad++ you can the Find in files which is located in the last tab when you hit CTRL+F
using NetBeans IDE you can lay your project out into a really decent code profiler and be able to see what your code is doing from a visual prospective.

Transferring a site - various file issues

I am putting an old website up on a new server and i've noticed various issues. Firstly, if i look at any of the files locally they all have double line spacing - anywhere there is a newline there has also been a blank line inserted. This is the same in netbeans and notepad++. Then, when i SFTP the files to the server and view them in Vi i see ^M at the end of each line. The final thing is that when i'm having issues making the site actually work, i've tracked this down to a common includes.php file which when i view it has been converted to a single line of code - i can still see ^M but there isnt a single newline in there. at the bottom of vi it actually says: "includes.php" [noeol]
I'm working locally on windows, i do have a Mac aswell i could try things on. My remote server is running Ubuntu 9
Please let me know if this question would be better on serverfault
Run the files through any of a number of standard utilities and save yourself a lot of time. I think dos2unix is usually on most distributions. If not it should be in a repository somewhere.
(Yes, this probably a serverfault question IMO.)
Snaken, had the same exact thing happen to me last night. I think I chalked it up to Netbeans, because it's never manifested itself in Notepad++ in several years of use. Good news is that if you open in notepad++ and re-do the returns, the tabs will reset themselves without fail. The bad news is that this is manual. For me, it was only three files, so no biggie.
This explains how to remove the ^m from line end: http://www.tech-recipes.com/rx/150/remove-m-characters-at-end-of-lines-in-vi/

Code displayed in one line after FTP upload/download

When I upload/download some HTML/CSS/… file to FTP server, sometimes something puts every line of code in one line making it completeply unreadable. That something happens every now and then and I’m still looking for an explanation for this behaviour. What could cause this?
It has to do with text file line endings and FTP transfer modes.
Text files in Windows use a combination of carriage return and line feed at the end.
Text files in Mac OS9 and down use carriage return only.
Text files in UNIX and its clones (including OSX) use line feed only.
It sounds like you're pulling a UNIX-style text file to a Windows system in binary mode and then trying to view it in an editor that doesn't understand these differences.
FTP clients have an ASCII (or ASC) transfer mode to do these conversions for you. It's not usually turned on by default, though, as it messes up binary files.
Two solutions are to use an editor that understands the differences or use an FTP client that allows you to tell it that specific file extensions should be transferred in ASC mode.
P.S. This is probably better asked on superuser or serverfault.
This problem arises when we are working with Notepad++, Notepad editors, main importantly hosting servers. I had an same issue and fixed it by opening file again through Dreamweaver and set the content properly and uploaded to server Again. Works fine.

Categories