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

    Join Date
    Jul 2000
    Posts
    29
    Rep Power
    0
    This is probably very simple, but I tried looking in php.net and some other web sites, but cannot find the solution to my problem.

    There is a file at a certain server www.someserver.com/somefile.txt, which contains text data of roughly this format:

    Name=Some name
    Birthdate=Some birth date
    Occupation=some occupation

    and so on.

    What I want to do in the php script is: fetch the information in the text file and take out just what, say, Occupation is = to. In this case, "some occupation". What is the best way to do this and what functions is it best to use here?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Posts
    114
    Rep Power
    16
    I would first use file() to turn each line of the file into an element of an array:
    http://www.php.net/manual/function.file.php

    Then you can use explode() with "=" as the separator to break down each name/value pair:
    http://www.php.net/manual/function.explode.php

  4. #3
  5. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    First you can read the files from the other server using file() function.

    $datas=file("www.someserver.com/somefile.txt");
    //read the text file from the other server.
    //and put it an array.

    //now loop that values.

    for($a=0;$a<count($datas);$a++){
    $values=explode("=",$datas);
    //split that row value based on '='.

    if ($values[0]=="Occupation"){
    //if row is occupation.
    echo $values[1];
    //print the occupation here.
    }
    }


    you may find out the occupation row using regex functions as well.




    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    29
    Rep Power
    0
    Thanks a lot guys, I got it working!!

Similar Threads

  1. Simple question regarding string evaluation
    By Lobsang in forum PHP Development
    Replies: 3
    Last Post: February 3rd, 2004, 02:28 PM
  2. Just a simple question!
    By Il Capitano in forum Perl Programming
    Replies: 1
    Last Post: January 23rd, 2004, 05:00 PM
  3. Replies: 3
    Last Post: January 7th, 2004, 04:23 PM
  4. Replies: 1
    Last Post: January 7th, 2004, 01:39 AM
  5. simple "mod_rewrite" question
    By ilikeitraw in forum Apache Development
    Replies: 6
    Last Post: January 3rd, 2004, 11:35 AM

IMN logo majestic logo threadwatch logo seochat tools logo