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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:30:31+00:00 2026-06-07T12:30:31+00:00

Good day guys, I am really nowhere to the guy who do PHP coding,

  • 0

Good day guys,

I am really nowhere to the guy who do PHP coding, so I am asking you.

I have file in txt format and in that file somewhere I am having line with “count: (n)”, where “(n)” can be any numeric value.

I need to search for count: (n), take the (n) value, sum it with +1 and save the file again.

So if I will have count: 10 it must be 10 + 1 = 11.

Thank you!

  • 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-07T12:30:33+00:00Added an answer on June 7, 2026 at 12:30 pm

    You’ll probably want to use some regex to parse the ‘count: n’ string from the file. Although my regex is kind of rusty, this pattern might help:

    $file = fopen('text.txt', 'r+'); // Open the file for reading and writing into the variable $file.
    $fileContents = file_get_contents($file); // Load the contents of the file to variable $fileContents.
    
    $countString = preg_match('/count: [0-9]+/', $fileContents); // Find instances of string 'count: n' where n is an integer, load the string into $countString.
    $count = preg_match('/[0-9]+/', $countString); // Find the integer from $countString, load into $count.
    $count++; // Iterate count up one.
    
    $newCountString = 'count: '.$count; // The 'count: n+1' string where n is the original integer.
    
    $newFileContents = preg_replace('/count: [0-9]+/', $newCountString, $fileContents); // Find the string 'count: n' and replace with 'count: n+1' where n is the original integer.
    fwrite($file, $newFileContents); // Write the new contents into the file.
    fclose($file);
    

    Good luck!

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

Sidebar

Related Questions

Good day to you guys I have an application that has a UITabBarController for
Good day I have a custom TextBox that has a IndicatorTextBox.ui.xml file as well
Good day guys, I've got quite a specific data model that I'm trying to
Good day guys, I've made a sweet favorites function with php mysql and ajax,
Good Day, I have two connection strings defined in my web.config file. <connectionStrings> <add
Good day, I have found a strange quirk in Vim that I can't explain
good day guys! in project, among others, have models: class Category(models.Model): name = models.CharField(max_length
Good day guys, I would like to inquire if anyone of you may have
Good day guys. I have the following struct and class, template <class T> struct
Good day, I have a class that implements the LoaderCallbacks, and hence have the

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.