Results 1 to 5 of 5

Thread: [RESOLVED] Split / Explode

  1. #1

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Resolved [RESOLVED] Split / Explode

    I have looked at php.net for this, with little result.

    I want to seperate one string into an array, here is what i want to achieve.


    PHP Code:
    $blah "css:syntax:copyright";

    // Split up, using : as the string pattern, i want these to go into an array

    Loop array

       
    // My code

    end
    No considering i havnt done arrays, or looping an array to the last instance i will look this up, and one know how to get the string split into an array? And if pos, how the array will loop?

    Cheers

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Split / Explode

    You haven't looked very hard, apparently. The function you want is called explode().
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Split / Explode

    Split and Explode both do the same thing, though Split I believe is just a shortcut and calls to explode anyway.

    syntax is: explode(delimiter, string, limit)

    where limit is the maximum number of positions you want in the array you're making. it's optional, and by default it will just split everything unless specified otherwise.
    Like Archer? Check out some Sterling Archer quotes.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Split / Explode

    Wrong. split() splits on a regular expression, explode() on a simple string. Thus, explode() is faster, and split() can hit you unexpectedly if your split string contains regex characters.

    This is a mistake that is easily made, because the reverse functions, join() and implode(), are in fact aliases for the same function, since you can't join on a regular expression.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Split / Explode

    Ah! I have used switch > for each and a switch statement.

    Right well im sorted, cheers guys (Y) spot on

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width