determining os for path separator?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Coder Droid

    #1

    determining os for path separator?

    After much searching, I can't seem to find any definitive way to
    determine which path separator to use. Obviously, it's ":" on nix, and
    ";" on windows ... so what's the best way to determine what OS I'm
    running on?

    I've got a functional hack in place. But ... well, it's a hack.
    Essentially, if my docroot begins with a "/" I just assume it's nix. So
    far, it works. But I can't imagine I'm the first person to need this.
    usenet searches haven't revealed much on the topic.

    --cd


  • Chris Hope

    #2
    Re: determining os for path separator?

    Coder Droid wrote:
    [color=blue]
    > After much searching, I can't seem to find any definitive way to
    > determine which path separator to use. Obviously, it's ":" on nix, and
    > ";" on windows ... so what's the best way to determine what OS I'm
    > running on?
    >
    > I've got a functional hack in place. But ... well, it's a hack.
    > Essentially, if my docroot begins with a "/" I just assume it's nix. So
    > far, it works. But I can't imagine I'm the first person to need this.
    > usenet searches haven't revealed much on the topic.[/color]

    There's the PHP_OS constant. It's been a while since I've done any PHP
    programming on Windows so I'm not sure exactly what it'll be set to on
    Windows, and a quick Google didn't quite clear that up either.

    However, this should be fairly safe:

    if(strpos(PHP_O S, "WIN") !== false) {
    $separator = ';';
    }
    else{
    $separator = ':';
    }

    --
    Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

    Comment

    • Coder Droid

      #3
      Re: determining os for path separator?

      > There's the PHP_OS constant.

      Weird. In all my searching, never came across that. Of course, now that
      I know it's there, I zoomed right into it in the documentation. So
      obvious now...

      Thanks so much for the tip.

      --cd


      Comment

      • Coder Droid

        #4
        Re: determining os for path separator?

        Well, PHP_OS isn't quite as helpful as I thought. Like you, I can't seem
        to find a definitive list of all possible OS's supported. So I'm left
        with "does it contain 'win' anywhere in it?" and, if not, let's just
        assume the path separator is :, which should work for everything else
        (linux, aix, darwin, etc.) Except for probably OS/2, but I doubt I'm
        going to have to worry about that that kind of portability for a while.

        I guess what PHP really needs is a global PHP_PATH_SEPARA TOR. :)

        --cd


        Comment

        • R. Rajesh Jeba Anbiah

          #5
          Re: determining os for path separator?

          "Coder Droid" <coderdroid@lik ethiswouldstops pam.hotmail.com > wrote in message news:<yZlbd.281 59$%e7.21573@fe 1.texas.rr.com> ...[color=blue]
          > After much searching, I can't seem to find any definitive way to
          > determine which path separator to use. Obviously, it's ":" on nix, and
          > ";" on windows ... so what's the best way to determine what OS I'm
          > running on?[/color]

          Perhaps...

          <?php
          echo PATH_SEPARATOR;
          print_r(get_def ined_constants( ));
          ?>

          --
          | Just another PHP saint |
          Email: rrjanbiah-at-Y!com

          Comment

          • 2metre

            #6
            Re: determining os for path separator?

            Coder Droid wrote:
            [color=blue]
            > Well, PHP_OS isn't quite as helpful as I thought. Like you, I can't seem
            > to find a definitive list of all possible OS's supported. So I'm left
            > with "does it contain 'win' anywhere in it?" and, if not, let's just
            > assume the path separator is :, which should work for everything else
            > (linux, aix, darwin, etc.) Except for probably OS/2, but I doubt I'm
            > going to have to worry about that that kind of portability for a while.
            >
            > I guess what PHP really needs is a global PHP_PATH_SEPARA TOR. :)[/color]

            You may want to peruse

            PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


            (Which includes the constant "PATH_SEPARATOR ")

            Comment

            • Coder Droid

              #7
              Re: determining os for path separator?

              > You may want to peruse[color=blue]
              >
              > http://www.php.net/manual/en/reserve...s.standard.php
              >
              > (Which includes the constant "PATH_SEPARATOR ")[/color]

              Well, slap my ass and call me sally. I don't know how many times I
              searched for "path" "separator" and just couldn't come up with
              *anything*. Seriously. I mean, I searched a lot, and I'm usually pretty
              good at that. Quite flummoxed over this obvious miss!

              [slinks away, but with thanks]

              --cd


              Comment

              • Chris Hope

                #8
                Re: determining os for path separator?

                Coder Droid wrote:
                [color=blue][color=green]
                >> You may want to peruse
                >>
                >> http://www.php.net/manual/en/reserve...s.standard.php
                >>
                >> (Which includes the constant "PATH_SEPARATOR ")[/color]
                >
                > Well, slap my ass and call me sally. I don't know how many times I
                > searched for "path" "separator" and just couldn't come up with
                > *anything*. Seriously. I mean, I searched a lot, and I'm usually pretty
                > good at that. Quite flummoxed over this obvious miss![/color]

                No matter how well you think you know a language there's always something
                new you didn't know... wish I'd known about that constant a few years ago.

                --
                Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

                Comment

                Working...