SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    put a column data into a text file one by one?

    he csv data as the following:
    Code:
      (first line)   price   url
    
      (second line)    $10   src="http://www.test.com/1455/"||src="http://www.test.com/image/1456/"||
    
      (third line)    $20  src="http://www.test.com/2260/"||src="http://www.test.com/2261/"||
    
          ....   ........
    now i want to put all the data from the url column into a text file. and shows the data one by one. namely:

    Code:
    http://www.test.com/1455/
    http://www.test.com/image/1456/
    http://www.test.com/2260/
    http://www.test.com/2261/
    ....
    now,i am stucked.

    a,i don't know how to extracte the url, and put them into a text file one line by one line.

    the following is my code, but it doesn't work.

    Code:
    $row = 1;
        if (($handle = fopen("test.csv", "r")) !== FALSE && ($handle2 = fopen("output.txt", 'a')) !== FALSE) {
            while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
                if($row > 1) {
                    fwrite($handle2, "{$data[1]}\n");
                }
                $row++;
            }
            fclose($handle);
            fclose($handle2);
        }

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,509
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by runeveryday View Post
    but it doesn't work.
    What happens? An error?


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
  •