malanno Posted June 17, 2015 Share Posted June 17, 2015 Hi: I'm a java programmer so a brief answer is what I'm looking for, or a point in a direction. I want access one record in a flat file semicolon delimited txt file? I'm having problems... Thank you # comments start with pound sign - ignore these and blank lines. VERSION 1.0 # Allowable keywords: SCD, CCD, BRD, ACU, WCU # Possible status indicators are: # SCD/CCD/BRD CHIP/TARGET # G = green online in use # R = red offline marked out # Y = yellow partial disabled # N = no color not installed idle # SCD num scd_status SCD 0 ; G ; # RACK 0 ---------------------------------------------------------------------------------------------- # CCD num ccd_status target_status temp details CCD 0 ; G ; GGNNNNNNNRRY ; 34C ; sn=NCC023e00350010 # BRD num brd_status chip0 chip1 chip2 chip3 chip4 chip5 chip6 chip7 temp details BRD 0 ; G ; G G G N N N N G ; 37C ; sn=BRD023d00420000 BRD 1 ; G ; N N N Y Y N N N ; 37C ; sn=BRD023d00420001 BRD 2 ; G ; G N N N R N N N ; 37C ; sn=BRD023d00420002 BRD 3 ; G ; N N N N R Y Y Y ; 37C ; sn=BRD023d00420003 BRD 4 ; Y ; N N N N R R R R ; 37C ; sn=BRD023d00420004 BRD 5 ; R ; R R R R R R R R ; 37C ; sn=BRD023d00420005 Link to comment https://forums.phpfreaks.com/topic/296884-php-flat-file-txt-semi-colon-table-echoing-one-record-in-the-table-to-a-html-page/ Share on other sites More sharing options...
Ch0cu3r Posted June 17, 2015 Share Posted June 17, 2015 I want access one record in a flat file semicolon delimited txt file? Which is? Maybe use fgetcsv Link to comment https://forums.phpfreaks.com/topic/296884-php-flat-file-txt-semi-colon-table-echoing-one-record-in-the-table-to-a-html-page/#findComment-1514192 Share on other sites More sharing options...
malanno Posted June 17, 2015 Author Share Posted June 17, 2015 I'm sorry I thought I bolded it, but I forgot. For example lets use the temperature from board 1 Link to comment https://forums.phpfreaks.com/topic/296884-php-flat-file-txt-semi-colon-table-echoing-one-record-in-the-table-to-a-html-page/#findComment-1514193 Share on other sites More sharing options...
Ch0cu3r Posted June 17, 2015 Share Posted June 17, 2015 Using fgetcsv you would use the semi-colon as the delimeter. As you loop over the lines when $data[0] starts with BRD, $data[3] will contain the value for the temperature column. The following code will build an array of temperatures, the board column (BRD 0, BRD 1) etc will be used as the index for the array. <?php $temps = array(); if (($handle = fopen("data.txt", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { if(substr(trim($data[0]), 0, 3) == 'BRD') { $board = trim($data[0]); $temp = $data[3]; $temps[ $board ] = $temp; } } fclose($handle); } Change data.txt to the filename your data is stored in. To show the temperature for board 1 (BRD 1) you would use echo $temps['BRD 1']; Link to comment https://forums.phpfreaks.com/topic/296884-php-flat-file-txt-semi-colon-table-echoing-one-record-in-the-table-to-a-html-page/#findComment-1514204 Share on other sites More sharing options...
malanno Posted June 17, 2015 Author Share Posted June 17, 2015 Thank you... you saved me... I will pay it forward when done with this project. William Link to comment https://forums.phpfreaks.com/topic/296884-php-flat-file-txt-semi-colon-table-echoing-one-record-in-the-table-to-a-html-page/#findComment-1514205 Share on other sites More sharing options...
malanno Posted June 19, 2015 Author Share Posted June 19, 2015 Would you be interested in teaching me php on a regular basis? I would gladly pay your hourly rate. William William Link to comment https://forums.phpfreaks.com/topic/296884-php-flat-file-txt-semi-colon-table-echoing-one-record-in-the-table-to-a-html-page/#findComment-1514307 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.