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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:14:24+00:00 2026-06-04T17:14:24+00:00

I have searched far and wide here but with no solution to my problem

  • 0

I have searched far and wide here but with no solution to my problem (php).

Scenario: User visits a login page with a pre-assigned registration number (in datafile.txt), when entering the number in the field, script searches file if number(s) exists.

If it does exist, goes on to the next step. When the next step has been completed, I would like it to automatically “delete” the number(s) originally used once done.

I believe a “search and replace” is the way to go, while searching for an “exact” match.

My data file would resemble the following: (datafile.txt)

0
12
123
1234
12345
123456

12, would not be the same as 123 if searched.

A script that I was so kindly given a few days ago is this to accomplish another task:

$numbers = file_get_contents("datafile.txt");

$uNumber = $_POST['uNum'];

if ( @preg_match( "/([^0-9]{$uNumber}[^0-9])/", $numbers ) ) {

echo "Numbers match";

}

What I tried to do for a new task, was the following but with no success:

$numbers = file_get_contents('datafile.txt', 'w+');

$uNumber = $_POST['uNum'];

if ( @preg_match( "/([^0-9]{$uNumber}[^0-9])/", $numbers ) ) {

$numbers = preg_replace('.$_Post["uNum"]','',$numbers);

echo "Existed but will be deleted from file. ";


} else {
echo "Message showed if not in file.";
}

Any help will be greatly appreciated.

  • 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-04T17:14:26+00:00Added an answer on June 4, 2026 at 5:14 pm

    How about this one:

    $index = file_get_contents("datafile.txt"); 
    $bodycont = str_replace("string to be replaced","what you want that string to be",$index);
    $fh = fopen("datafile.txt","w");
    fwrite($fh,$bodycont);
    fclose($fh); 
    

    OR:

     $file = file("datafile.txt", FILE_IGNORE_NEW_LINES);
     foreach($file as $text) {
     $test[] = $text;
     }
    
    //get the size of the array
    
    $arraysize = sizeof($test);
    
    //use for loop to check if that string is found in the array and replace it
    
    for($x=0;$x<$arraysize;$x++)
        {
                   if($test[$x] == "$uNumber")
                    {
    
                    }
                    else
                    {
                       $newarray[] = $test[$x];
                    }
        }
     $stringData = implode("\n",$newarray );
     $fh = fopen("datafile.txt","w");
     fwrite($fh,$stringData );
     fclose($fh);
    

    this should somehow work. 😀

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

Sidebar

Related Questions

I have searched far and wide on the Internet but have not found anything
I have searched far and wide on this one, but haven't really found a
this is a PHP related question. I have searched far and wide for a
I've searched far and wide for suggestions and solutions to this problem, but I'm
Good day, I have searched far and wide but all I can find is
I have searched many threads so far but cant seem to find a solution.
I have searched high, low, far and wide but can not find anything on
I have searched/Googled around but I'm struggling with the following problem. I am building
I have searched for hours now and haven't found a solution for my problem.
I've searched pretty far and wide for the past several days and have little

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.