Line endings difference Windows <-> Linux
Patrick Asselman
iceblink at seti.nl
Tue Jun 11 09:54:33 UTC 2013
On 2013-06-11 11:08, Bo Berglund wrote:
> On Tue, 11 Jun 2013 09:59:47 +0200, Patrick Asselman
> <iceblink at seti.nl> wrote:
>
>>PHP does not care how you end your lines for interpretation of the
>>code.
>>
>>BUT there are some risks, for instance if you print a string, the
>>string may come out differently, depending on how you coded it. Or if
>>you read a line of text from a file.
>>
>>My suggestion would be to find a good FTP program, and to make sure
>> the
>>files are converted as they are transferred.
>>For instance FileZilla has a sane default setting and knows that php
>>files are basically text files that need converting when transferred
>>from one system to the other. But all ftp programs have such a
>> setting
>>(set "transfer type" to "auto" will do the trick).
>
> What I was after was really to confirm weather or not I can stop
> worrying about the line endings. Seems from your reply that for PHP
> this is true as long as I don't have string manipulation code in php
> that splits a string across several lines like:
>
> $txt = " my new text here and then continue on the
> following line like this";
Correct. Unfortunately I was not able to find a good reference that
show this to be the case, but from the top of my head I remember having
some files on a server with lots of ^M in them, and PHP does not have a
problem with that.
> Whereas this will work:
> $txt = " my new text here and then continue on the " .
> "following line like this";
>
> Each substring contained within a single line...
Your example simply concatenates both strings without a newline, but
yes that is the general idea. Something like
$txt = "first string\n" .
"second string";
or even better
$txt = "first string".PHP_EOL.
"second string";
> Concerning the development and hosting:
> I develop in my own environment using a Win7 PC as my main
> workstation
> and a linux virtual machine with lamp-server as the test site.
>
> But the hosting is done on Network Solutions and there I have no
> control at all over almost anything, especially I do not have an
> account that can be logged on and run commands on the server.
>
> So rsync is not an option here, I must use an FTP client like
> Filezilla. It will autodetect files, but I found that I have to:
> 1) Add the extensions that should be treated as ASCII
Mine already has a lot of types predefined, but maybe that is because I
use a portable standalone version from portableapps.org that someone
precompiled in a particular way.
There is also a setting in Edit; Settings; Transfers; File Types;
Default transfer type -> set to Auto.
> 2) Not use sFTP because then everything seems to be transferred as
> binary.
Afaik this is not the case, but I havent tested it.
> 3) "Know" which files to transfer (i.e. which have been edited since
> the last transfer) because it is not an option to always transfer
> everything due to Internet upload bandwidth being so pitiful.
Yes this is true for most FTP clients.
For Filezilla you can set a default "file exists" action, and set it to
"overwrite if newer", then transfer the main folder (which will
automatically include subfolders).
And I'm sure there are programs out there that can keep an entire
directory tree in sync, in a more or less intelligent way. Unfortunately
I don't know of any, because i've had no need for one.
Best regards,
Patrick Asselman
More information about the ubuntu-users
mailing list