PHP Code Syntax (help please)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Smut
    Confirmed User
    • Sep 2002
    • 654

    #1

    PHP Code Syntax (help please)

    Here's what I'm wanting to do...

    I have a little script that outputs a few parts in 1 string...
    Example:

    Form input:
    Name
    ICQ
    Email

    The script writes the data to file in the format of:
    bob jones:5551212:[email protected]

    Seperated with the ":".

    Now, I'm trying to display each line on a seperate page formatted like so:

    Name: Bob Jones
    ICQ: 5551212
    Email: [email protected]


    I know there's something with the explode() function, or split()... but, not exactly sure if this is the best way to do it, and if it is, I'm not quite sure of the syntax.

    Any help is appreciated.

    Thanks
  • JSA Matt
    So Fucking Banned
    • Aug 2003
    • 5464

    #2
    PHP Code:
    <?php
    //    List
    
        $data = file("file.txt");
        
        if (count($data) < 0)    {
            for ($i = 0; $i < count($data); $i++)    {
                list($name,$icq,$email) = explode(":", $data[$i]);
                
                echo "Name: " . $name . "<BR>";
                echo "ICQ: " . $icq . "<BR>";
                echo "Email: " . $email . "<BR><BR>";
            }
        } else {
            echo "Data File Empty";
        }
    ?>

    Comment

    • Smut
      Confirmed User
      • Sep 2002
      • 654

      #3
      Originally posted by JSA Matt
      PHP Code:
      <?php
      //    List
      
          $data = file("file.txt");
          
          if (count($data) < 0)    {
              for ($i = 0; $i < count($data); $i++)    {
                  list($name,$icq,$email) = explode(":", $data[$i]);
                  
                  echo "Name: " . $name . "<BR>";
                  echo "ICQ: " . $icq . "<BR>";
                  echo "Email: " . $email . "<BR><BR>";
              }
          } else {
              echo "Data File Empty";
          }
      ?>
      Great! Thanks! That's what I was looking for.

      Comment

      Working...