We help IT Professionals succeed at work.
Get Started

Load .txt into PHP array and only output certain rows

raynman1972 asked
Last Modified: 2012-05-09
I have a text file that I need to open via PHP and load into an array, this much seems to work so far.  What I am having problems with is I only want to display rows where Employee ID equals a specified value.

This is something that I cannot get via Mysql and can only get out of a .txt file.  How can I get it to only echo the lines where $value= 141991 (for example)?

Employee ID      Punch Time
141991      5:43:00
142353      5:37:00
145106      6:52:00
149205      5:39:00
149205      9:41:00
149229      6:39:00
149244      9:00:00
149319      6:43:00

$myfile = '../Attendance/current-punches.txt';
$lines = file($myfile);   

$value= "204445";


if ($lines[i] = $value)
echo $lines[$i];}


Open in new window

Watch Question
Expert of the Year 2008
Top Expert 2008
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE