#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    43
    Rep Power
    15

    Split a variable by characters.


    Hi,

    I have a variable $subject which contains 4 bits of info seperated by "::" for example

    username:assword::number::title


    What i need to do is split $subject into 4 and assign each bit of text to a variavle. So the out come will look something like:-

    $username = "username"
    $password = "password"
    $number = "number"
    $title = "tilte"

    I think i should be using the "explode" command, but i cant get it to work. Something like:
    PHP Code:
    $subject explode("::"$test); 
    Any help would be very much appreciated.

    Regards, Ben.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    USA
    Posts
    477
    Rep Power
    58
    PHP Code:
    list($username$password$number$title) = explode('::'$string); 
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    43
    Rep Power
    15

    Wink Perfect...


    Great stuff, exactly what i was after.

    Thanks very much for the promt reply.

    Ben.

IMN logo majestic logo threadwatch logo seochat tools logo