Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post

    Having problems with split()

    Hey guys.... I'm trying to use split() to split some data into an array but it's not working.... it keeps being returned as one line.

    Here is my code..

    PHP Code:
    foreach ($data as $line) {
     
    $line trim($line);
     
    $parts split('~\s+~'$line2);
     
    // ...

    Here is some example data that I am using..

    Code:
    PAAB 	12345
    PAAD 	12345
    PAAI 	12345
    PAAJ 	12345
    PAAM 	12345
    PABD 	12345
    PABG 	12345
    PACB 	12345
    PACM 	12345
    Thanks for any help!

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    What's the type of your variable $data? 2D array?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Sorry....... the text I provided is retrieved by using file().

  • #4
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Split doesn't use delimiters (which is what I am going to assume the ~ characters are).

    Leave your code as is, except replace split() with preg_split().

  • #5
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Thanks for that!


  •  

    Posting Permissions

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