Avatar of trevor1940
trevor1940

asked on 

Test if unique ID is in log file

I have a log file something like bellow

How do I test if an ID exist and type = ABC?

log.txt

ID|TYPE|DATE
123|XYZ|2017-03-07
123|ABC|2017-03-08
124|XYZ|2017-03-08

Open in new window


PHP

<?php
error_reporting(E_ALL);
$Data = explode('|', file_get_contents("log.txt"));
trace($Data);
$ID = 123;
if($Data[$ID]){
  echo "found $ID";
  }

function trace($arr){
    echo "<pre>";
    print_r($arr);
    echo "</pre>";
}//end trace

Open in new window

PHP

Avatar of undefined
Last Comment
trevor1940
ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of trevor1940
trevor1940

ASKER

I hadn't realized the size of the file mattered

The log file currently doesn't exist so can be in what  ever format I want but is likely to grow daily as each time the application is run new lines will be created maybe 10 per day.

Maybe I need further explanation

each time it's run a directory is read with 1 or more files in
within each file a ID and TYPE is read
I need to test it hasn't been processed  before potentially the same ID can be used up to 3 times depending on type  however the vast majority will be once

so I would open the log file once and as I read the directory test if that file ID / TYPE has been processed before if not then process the file
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

"Size matters" within some broad constraints.  When we're talking about adding 10 lines a day to a file, it will take years before size matters!  Any of the solutions shown here will probably be OK, but as usual, the devil is in the details.  If the test case we worked with is not truly representative of the live data, then there may be additional considerations and changes needed.
Avatar of trevor1940
trevor1940

ASKER

Thanx for your help and info
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo