supose we have

$artist = \"Sting, Tracy Chapman, Bob Marley & Sade\"

and we wanna split it in an array

the result of that \"split\" will be the following array:

$art[0] = \"Sting\"
$art[1] = \"Tracy Chapman\"
$art[2] = \"Bob Marley\"
$art[3] = \"Sade\"

in other words split $artist using \", \" (comma and space) or \" & \" (space & and space)

I think that we gotta use the split function
and some regex, the proble that i m not very familiary with any of them.

    I use arrays like this userlist:

    <userlist.lst>

    user1#user2#user3#user4

    You can easily load it from file to array using function LoadFromFile (have to code it first {string LoadFromFile ($filename)}):

    $users = split ("#", LoadFromFile ("userlist.lst"));

    Now I can deal with the users easily with for-function or directly with row number.

    for (£i = 0; $i < count ($users); $i++)
    if ($users[$i] == $user)
    print "User $user found!";

    You also save it easily with SaveToFile (have to code it first {void LoadFromFile ($filename, $data)})🙂:

    SaveToFile ("userlist.lst", implode ("#", $users));

    Now it's on your harddisk on it's original form:

    <userlist.lst>

    user1#user2#user3#user4

    To add new user (item) to your list just use array_push ($users, $newitem) after load-function.

    Hope this helps some1 to handle lists and that sort of stuff. Just send mail to me if you have need those FileHandling-functions.

      well it s not exactly what i m looking for but this gave me an idea about something else that i m working on thanx

      And plz post those function so everybody can enjoy them.

        • [deleted]

        The split and explode functions are clearly explained in the manual. Read it.

          Try something like this:

          <?php

          $varTest = "Sting, Tracy Chapman, Bob Marley & Sade";

          /do this just to make sure.
          You could just do the variable assignment
          instead, but I like to check for conditions.
          /

          if(ereg(" & ",$varTest)) {

          $varTest = ereg_replace(" & ",", ",$varTest);

          }

          $varArtists = explode(", ",$varTest);

          //now make sure it worked.
          for($i = 0;$i < count($varArtists);$i++) {

          echo($varArtists[$i] . "<br>\n");

          }

          ?>

          Its in the manual, but I know how daunting that can be if you've never used the functions before. HTH,

          Jim Hawley

            Write a Reply...