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

  • Home
  • SEARCH
  • 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 8684039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:11:58+00:00 2026-06-12T22:11:58+00:00

I am looking for a suggestion on this: I have a text file called

  • 0

I am looking for a suggestion on this:

I have a text file called movies.txt with about 900 lines, which contains one movie name per line. However, I would like to remove the year the movie has been released using PHP (which I am new to)

The format is basically:

A Nous la Liberte (1932)
About Schmidt (2002)
Absence of Malice (1981)
Adam's Rib (1949)
Adaptation (2002)
The Adjuster (1991)
The Adventures of Robin Hood (1938)
Affliction (1998)
The African Queen (1952)

So I am looking for a way to open the text file, reading it line by line and removing the (YEAR) values while also removing the space before the (YEAR).

Then I would like to save it as newmovies.txt

Would be great if you could show and explain me a solution that works for my needs. I am still very new to PHP (started a week ago) so it’s all still magic to me.

  • 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-12T22:12:00+00:00Added an answer on June 12, 2026 at 10:12 pm

    You can read a file line-wise using the file() function. Then foreach over that and strip lines until the opening parenthesis.

    For example

    foreach (file($fn) as $line) {
         $output[] = strtok($line, "(");
    }
    

    You may need to trim the extra space and add linebreaks again.

    So a regex might be simpler and also asserts some structure without blindly cutting things off:

    $text = file_get_contents($fn);
    $text = preg_replace('/\s*\(\d+\)/m', '', $text);
         #  \s* is for spaces and \d+ is a placeholder for numbers
    

    Then save that back.

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

Sidebar

Related Questions

I have a text file with 50k+- lines and each line contains data which
Say I have the following style of lines in a text file: 12 34
The setup: I have a standard .php file (index.php) that contains two includes, one
I have some text that is in a file. I want to encrypt this
I'm using python 2.6 on linux. I have two text files first.txt has a
I'm looking to combined multiple text files with a delimiter and their file name
I have been reading a lot about this - I feel like I'm very
I am looking for something like this on DataGridView: Image | Text | Text
i'm supposed to write code which when given a text file (source code) as
Given a yaml file that contains html , like this: template : |+ <div>Hello,

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.