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 8592323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:43:34+00:00 2026-06-11T23:43:34+00:00

I would like to extract 2 pieces information from a text file using the

  • 0

I would like to extract 2 pieces information from a text file using the substr method in PHP. Some sample lines are as follows

 CON8101 Residential Building/Estimating 6 hrs/w 
 CON8411 Construction Materials I 4 hrs/w
 CON8430 Computers and You 4 hrs/w

I need to extract the number of hours each course requires. Is the function I wrote correct to extract the number from the back of the line? I have come up with the function:

            function GetCourseHours($couseList)
    {//using 7 character placements from the end, taking 1 value (number)
        $courseHours = substr(courseList, -7, 1);
    }

And next, to extract everything except for the number of hrs/w, like CON8101 Residential Building/Estimating. I’m not sure how to express in substr to extract everything but the last 7 character spaces from the line. To get course name and ID only.

            function GetCourseName($courseList)
    {//how do I only emit the last 7 placements of the txt string?
        $courseName = substr(courseList, ..., ...)
    }
  • 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-06-11T23:43:35+00:00Added an answer on June 11, 2026 at 11:43 pm

    The PHP documentation on substr covers all of the information you need to know about its behavior:

    function GetCourseName($courseList)
    {
        $courseName = substr($courseList, 0, -7);
    }
    

    The relevant portion of that documentation for your application is:

    If length (the 3rd argument) is given and is negative, then that many characters will be
    omitted from the end of string (after the start position has been
    calculated when a start is negative).

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

Sidebar

Related Questions

I would like to extract some lines from a text file, I have started
I would like to extract the GPS EXIF tag from pictures using php. I'm
I would like to extract portion of a text using a regular expression. So
I would like to extract items from this sample html, more specificly, i would
Using Php I would like to extract the current Url of a page including
Hello! I would like to extract all citations from a text. Additionally, the name
I would like to extract static text from between HTML tags: <p> text here
I would like to extract all text from subnodes of a specific document, AND
I would like to extract some text between two points in a string, in
I have an HTML file and would like to extract the text between <li>

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.