Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6353279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:23:02+00:00 2026-05-24T22:23:02+00:00

I have been given a textfile which contains data on time sheet. That line

  • 0

I have been given a textfile which contains data on time sheet. That line contains a name and a department and their time out/in.The code below allows me to display the entire textfile but I want to read in the values by name and department from file and want to display that .

<?php
$file = fopen("C:\Bhrugisha mam.txt","r") or exit("Unable to open file!");
while(!feof($file))  
{
echo fgets($file). "<br />";
}
fclose($file);
?>

this is some data from my text file…

                                                               VCANTECH - Log Report


                 6                 Bhrugisha Shah
                 Hr
                 Department:         HR
                 August, 2011                                                                                           Page 1 of 2
                 -----------------------------------------------------------------------------------------------------------------
                 Date :    01/Aug/2011         Shift : 1       (     9:30:00 AM     To      6:30:00 PM     )
                                     LOG TIME :    9:23:00 AM                 LOG TYPE :    IN
                                     LOG TIME :    1:55:00 PM                 LOG TYPE :    OUT
                                     LOG TIME :    2:18:00 PM                 LOG TYPE :    IN
                                     LOG TIME :    6:45:00 PM                 LOG TYPE :    OUT
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:23:03+00:00Added an answer on May 24, 2026 at 10:23 pm

    This should get you there

    $input = fread( $file, filesize("PATHTOFILE"));
    
    preg_match("%Department:[\s]{1,}[a-z]{1,}%i", $input, $department);
    
    var_dump($department);
    
    //OUTPUT array(1) { [0]=> array(1) { [0]=> string(22) "Department: HR" }
    
    preg_match_all("%log time :    [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2} (AM|PM)                 LOG TYPE :    (IN|OUT)%i", $input, $matches);
    
    var_dump($matches);
    
    /*
     OUTPUT 
     array(3) { [0]=> array(4) { [0]=> string(57) "LOG TIME : 9:23:00 AM LOG TYPE : IN" [1]=> string(58) "LOG TIME : 1:55:00 PM LOG TYPE : OUT" [2]=> string(57) "LOG TIME : 2:18:00 PM LOG TYPE : IN" [3]=> string(58) "LOG TIME : 6:45:00 PM LOG TYPE : OUT" } [1]=> array(4) { [0]=> string(2) "AM" [1]=> string(2) "PM" [2]=> string(2) "PM" [3]=> string(2) "PM" } [2]=> array(4) { [0]=> string(2) "IN" [1]=> string(3) "OUT" [2]=> string(2) "IN" [3]=> string(3) "OUT" } }
    */
    
    foreach($matches[0] as $row){
    
        preg_match("%[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2} (AM|PM)%", $row, $logTime);
        //var_dump($logTime);
        //OUTPUT array(2) { [0]=> string(10) "9:23:00 AM" [1]=> string(2) "AM" } array(2) { [0]=> string(10) "1:55:00 PM" [1]=> string(2) "PM" } array(2) { [0]=> string(10) "2:18:00 PM" [1]=> string(2) "PM" } array(2) { [0]=> string(10) "6:45:00 PM" [1]=> string(2) "PM" }
        $logTime = $logTime[0];
    
        preg_match("%(IN|OUT)%",$row, $inOut);
        var_dump($inOut);
        //OUTPUT array(2) { [0]=> string(2) "IN" [1]=> string(2) "IN" } array(2) { [0]=> string(3) "OUT" [1]=> string(3) "OUT" } array(2) { [0]=> string(2) "IN" [1]=> string(2) "IN" } array(2) { [0]=> string(3) "OUT" [1]=> string(3) "OUT" }
        $inOut = $inOut[0];
    
    }
    

    I would recommend making some edits to the regex’s, as I just copy and pasted the spaces. [\s]{1,} can be used in place of the crazy spaces 😛

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a text file which contains some numerical data. Of that text
I have been given two different Microsoft Word document that my virus scanner has
I have been given a DLL (InfoLookup.dll) that internally allocates structures and returns pointers
I have been given a specification that requires the ISO 8601 date format, does
I have been given a task to display data on an ASP .net page
I have been given a problem to decrypt this text: 3e47b75000b0924b6c9ba5759a7cf15d which is supposedly
I have been given task to check for url that site:domain (If index in
I have been given the following: <div class=elf>Label 1</div> <div class=eff>Data 1</div> <div class=elf>Label
I have been given a fairly large database stored in Microsoft Excel, which I
I have been given a task to create a Python file that will take

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.