Giter Site home page Giter Site logo

Not exploding by PHP_EOL about phpdotenv HOT 7 CLOSED

vlucas avatar vlucas commented on May 2, 2024
Not exploding by PHP_EOL

from phpdotenv.

Comments (7)

vlucas avatar vlucas commented on May 2, 2024

I'm not sure. PHP_EOL should be your system's end of line character. I just did some research though and it seems like "\r\n" is best for wide compatability. Can you verify that explode("\r\n", ... ) works on your system?

from phpdotenv.

jtwebb avatar jtwebb commented on May 2, 2024

"\r\n" doesn't work. It still doesn't break each line into a value. It just throws everything into $lines[0] (same as PHP_EOL). It's odd that it doesn't work since I have the same setup on a different local virtual server and deployment server and they both work fine. There's nothing different about this setup, yet it still won't work without using "\n".

from phpdotenv.

harm-less avatar harm-less commented on May 2, 2024

I've the same problem. I'm using IIS to simulate PHP and to parse the Dotenv class.
Apparently the PHP_EOL doesn't contain any line-break information, but explode("\n", ... ); does work on my system.

Update:
At a closer look, I think the PHP_EOL does contain a "\r\n", however, it of course doesn't fix the problem because only the "\n" here.

And I found a similar topic about this: avalanche123/doxphp#7

from phpdotenv.

QWp6t avatar QWp6t commented on May 2, 2024

I don't think you should rely on PHP_EOL.

I would recommend using something like this: http://stackoverflow.com/questions/11066857/detect-eol-type-using-php

from phpdotenv.

harm-less avatar harm-less commented on May 2, 2024

It seems like PHP_EOL is a good practice when creating new lines dynamically, not when exploding.
http://stackoverflow.com/questions/4975411/when-do-i-use-php-eol-instead-of-n-and-vice-versa-ajax-jquery-client-problem

Perhaps you can use the first answer:
$lines = array_map("rtrim", explode("\n", $fc));
Or something similar since it will break on old macs. Perhaps something like this, I've tested this and it works fine at my system:
$lines = preg_split('/\r\n|\r|\n/', $fc);

from phpdotenv.

QWp6t avatar QWp6t commented on May 2, 2024

This worked for me

ini_set("auto_detect_line_endings", true);
$lines = file($filePath);

It uses PHP's auto line detection (see: L852), which appears to be more or less the same as the last line of @harm-less's post.

I'd recommend going with his method on the off chance a user might not be happy with changing an ini setting (although you could use ini_get() and then change it back afterwards, but whatever; doesn't seem like that's necessary).

from phpdotenv.

vlucas avatar vlucas commented on May 2, 2024

This has been fixed.

from phpdotenv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.