SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Location
    London
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with tokenizing

    I have been trying to tokenize two words separated by ; by using strtok() function. I can get the first word in a variable but how do I get the second?

    e.g:
    $string1 = "word1;word2";

    $x = strtok($string1, ";");

    Thanks
    -- | StEaLThEn |--

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well this something I hacked up from php.net
    PHP Code:
    $string1 "word1;word2"
    $x strtok($string1";"); 
    while(
    $x) {
        
    $words[] = $x;
        
    $x strtok(";");
        }
    print 
    $words[0]; //prints word1
    print $words[1]; //prints word2 

    I think you would be better off using something like explode() here unless I am missing your point.


    PHP Code:
    $string1 "word1;word2"
    $words explode(";"$string1); 
    print 
    $words[0]; //prints word1
    print $words[1]; //prints word2 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Location
    London
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you freddy,
    I actually forgot explode() which certainly a better choice.
    -- | StEaLThEn |--


Bookmarks

Posting Permissions

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