SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2004
    Location
    canada
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow explode() function

    Hy, Im trying to insert into an array part of a string from a text file.

    The text file contains characters that I wish to insert in the array. A --> * character is between each entry that I want to separate in the array. Therefore it looks like this:

    Code:
    // Write all data to people.txt
    $fp = fopen ( "people.txt", "a");
    fwrite ($fp, $inputString);
    fclose ($fp);
    
    $tokensArr = Array();
    
    $filename = "people.txt"; 	// File which holds all data
    $fp = fopen ( $filename, "r");
    $content = fread( $fp, filesize( $filename ) );
    fclose($fp);
    
    $tokensArr = explode ("*",$content);
    
    echo sizeof($tokensArr);
    When I view the sizeOf the Array it shows that I have 2 elements in the array, but in fact I only have one entry (only one * character in people.txt)

    people.txt:
    Code:
    *Cooper<br>Rockstar Poser<br>No<br>
    Why is the size of the array 2 and not 1 ?
    Patrick S.
    Comp. Sci. & Digital Image & Sound Undergrad
    Concordia University

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    When the string is splitted at the * character, you will get one index with the data before the character (in this case nothing) and one index with the value after (in this case "Cooper<br>Rockstar Poser<br>No<br>").

    Yours, Erik.


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
  •