#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    4
    Rep Power
    0
    Maybye this has been ask a hundred times...

    I got a textfile who stores the users input.
    I got it work to read each line in an Array but further i need to extract the data into single strings.

    the textfile looks like
    name|email|...
    I know i want to be able to use them as $name and $email.....after i read them from the .txt file

    Tx a lot

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

    Join Date
    Feb 2000
    Location
    Den Laeghe Landen
    Posts
    107
    Rep Power
    15
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by tapir:
    I got it work to read each line in an Array but further i need to extract the data into single strings.
    [/quote]
    First a question for u:
    what is exactly in the array?
    * all lines each as one arrayelement:
    ("name0|email0|...", "name1|email1|...",...)

    OR:
    * one line split up into words as one array:
    ("name0", "email0", ...)

    maybe, i can help you, if i know this.

    Greetz,
    EyE


    ------------------
    --
    ...tiktak...tiktak...
    --
    ...Tommyknockers, Knocking On Your Door...
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    4
    Rep Power
    0
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>what is exactly in the array?
    * all lines each as one arrayelement:
    ("name0|email0|...", "name1|email1|...",...)
    [/quote]
    the array of the .txt file looks like above..
    *exactly it looks like array0= name|email|...
    array1= name|email|...
    but i'm still not able to get these array values into $trings which i can use for further handling....

    is there a use of regularexpresions needed ???

    Tx for help....

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Den Laeghe Landen
    Posts
    107
    Rep Power
    15
    Okay, so each array-element contains one entire line, which still has to be split up at the '|'-signs.
    Do something like this:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $lines = Array("name0|email0", "name1|email1|"); //etc.
    for each $line in $lines{
    $lineparts = explode ("|", $line);
    // now do something with the data, e.g.
    echo "the name is " . $lineparts[0] . " with email: " . $lineparts[1] . "n";
    }
    [/code]
    ( so, explode splits up a string at the specified delimiter, and returns an array with the split parts)
    see also: http://www.php.net/manual/function.explode.php
    or for general string-functions: http://www.php.net/manual/ref.strings.php

    GoodLuck!

    EyE

    ------------------
    --
    ...tiktak...tiktak...
    --
    ...Tommyknockers, Knocking On Your Door...

    [This message has been edited by EyE (edited June 08, 2000).]
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    7
    Rep Power
    0
    if you have a string variable with value like:
    name|email|...
    you can convert it into an array by doing
    $array_name = split("|", $string_name);

    BUT... this morning i've just find out that you can't use "|" character as a delimiter...

    Best regards,
    Tata
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    300
    Rep Power
    15
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by weddeh:
    if you have a string variable with value like:
    name|email|...
    you can convert it into an array by doing
    $array_name = split("|", $string_name);

    BUT... this morning i've just find out that you can't use "|" character as a delimiter...

    Best regards,
    Tata
    [/quote]

    You can, you just need to escape it, i.e. split("|"$string). The split() function in PHP uses regexp engine (like in Perl), so you need to escape the pipe (|) since it is used in regexps (the "or" operator). If you want to split a string into an array without this hassle, use explode(), i.e.:
    $array = explode("|", $string).

Similar Threads

  1. sort: find duplicate string elements in array
    By sciencelife in forum Java Help
    Replies: 3
    Last Post: January 27th, 2004, 01:29 PM
  2. sendmail installation problem on Linux
    By abuschr in forum Linux Help
    Replies: 0
    Last Post: January 14th, 2004, 09:08 AM
  3. Help needed with array sorting
    By frontsys in forum PHP Development
    Replies: 1
    Last Post: January 13th, 2004, 04:56 PM
  4. removing openssl rh9
    By odave in forum Linux Help
    Replies: 0
    Last Post: January 11th, 2004, 10:51 PM
  5. multi-dim array from "while" loops (?) help needed
    By integer99 in forum PHP Development
    Replies: 2
    Last Post: December 12th, 2003, 05:06 PM

IMN logo majestic logo threadwatch logo seochat tools logo