explode the / variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maheswaran
    New Member
    • Mar 2007
    • 190

    explode the / variable

    Hi ,

    i have the variable $path="root/sample";

    i want to explode this variable by /, but while using

    explode("/",$path);

    i got parse error, how we can do this
  • secmazec
    New Member
    • Mar 2009
    • 34

    #2
    I have 2 ideas what can cause it.

    1. you don't assign explode into variable, namely array
    Code:
    $path="root/sample";
    $dirs = explode( "/", $path);
    // $dirs[0] = "root", $dirs[1] = "sample";

    2. Your separator is a special character, you need to comment it with backslash
    Code:
    $dirs = explode( "\\", $path);

    Comment

    • Nert
      New Member
      • Nov 2006
      • 64

      #3
      Originally posted by maheswaran
      Hi ,

      i have the variable $path="root/sample";

      i want to explode this variable by /, but while using

      explode("/",$path);

      i got parse error, how we can do this
      i tried to use your code and it works fine to me.
      Code:
      $path="root/sample";
      $dir = explode("/",$path);
      echo $dir[0];
      echo $dir[1];

      Comment

      • maheswaran
        New Member
        • Mar 2007
        • 190

        #4
        Yes guys,

        It is not work in my system. So that am confused.....

        Comment

        • Nert
          New Member
          • Nov 2006
          • 64

          #5
          Originally posted by maheswaran
          Yes guys,

          It is not work in my system. So that am confused.....
          Have you tried using a different separator? instead of using "/" try the other character to test whether the problem is really on your system or just on the codes.

          Comment

          • maheswaran
            New Member
            • Mar 2007
            • 190

            #6
            ya will do and let you know

            Comment

            Working...