Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Question read a file - comma separate and output to screen

    hi,

    Can someone please help?
    I need a bit of PHP code that reads data in a file and comma separates it and outputs it to the screen?!

    here is what i have written so far:
    Code:
    <?PHP
    
    $file_handle = fopen("colors/rgb.csv", "r");
    
    while (!feof($file_handle) ) {
    
    $line_of_text = fgetcsv($file_handle, 1024);
    
    print $line_of_text[2] . $line_of_text[3] . $line_of_text[4] . "<BR>";
    
    }
    
    fclose($file_handle);
    
    ?>
    this outputs a list of RGB numbers for example:

    Ref_RRef_GRef_B
    149119109
    190171158
    200161148
    154109111
    1088888
    1408579

    I would like to now convert these numbers (each line) to HEX colors

    please help?!

    thanks
    Last edited by jarv; 10-14-2009 at 04:22 PM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,495
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    PHP Code:
    <?PHP

    $file_handle 
    fopen("colors/rgb.csv""r");

    while (!
    feof($file_handle) ) {

    $line_of_text fgetcsv($file_handle1024);

    // Convert DEC to HEX.
    $val1=dechex($line_of_text[2]);
    $val2=dechex($line_of_text[3]);
    $val3=dechex($line_of_text[4]);

    print 
    $val1 $val2 $val3 "<BR>";

    }

    fclose($file_handle);

    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •