Delete a line of text in a txt file

Hello everyone, I need help with two things.
Considering a data.txt file in which the data sent by a form are transcribed, line by line, with name and date of transmission.

Example:
Name1; xxxxxxxxxxxxxxxxxxx; 02/23/2019
Name2; xxxxxxxxxxxxxxxxxxx; 03/30/2019

I need a code that deletes each line one year after the date stamped on it.

Furthermore, I would need a form, for users, through which they can autonomously delete the line corresponding to their name when they wish.

Example:
-schermata-2019-05-27-alle-13-11-05.png

Can it be done?
Since I am not an expert, I would be so grateful if you would like to be detailed and exhaustive in any explanations. Thanks a lot

(I don’t know how to post the code I’m using)

Copy it, add three backticks on a new line, press enter, paste the code.

Thank you. This is my code:

<?php
if(isset($_POST["user"]) && isset($_POST["pass"]))
{
    // check if user exist.
    $file=fopen("data.txt","r");
    $finduser = false;
    while(!feof($file))
    {
        $line = fgets($file);
        $array = explode(";",$line);
        if(trim($array[0]) == $_POST['user'])
        {
            $finduser=true;
            break;
        }
    }
    fclose($file);
    
    // register user or pop up message
    if( $finduser )
    {
        echo $_POST["user"];
        echo ' existed!\r\n';
        include 'reg.html';
    }
    else
    {
        $file = fopen("data.txt", "a");
        $date = new DateTime();
        $date = $date->format("Y-m-d");
        $hash = hash ("sha256", $_POST["pass"]);
        fputs($file,$_POST["user"].";".$hash.";".$date."\r\n");
        fclose($file);
        echo $_POST["user"];
        echo "<meta http-equiv=\"refresh\" content=\"0; url=./success\">";
    }
}
else
{
    include 'reg.html';
}
?>

Sorry, but the code becomes compressed

That wasn’t a backtick, `

As far as deleting a specific line,

$contents = file_get_contents($dir);
$contents = str_replace($line, '', $contents);
file_put_contents($dir, $contents);

Sorry, English is not my language and I searched backtick with the translator. Thanks for the reply, now I try to understand how to apply this code to what I need

Sponsor our Newsletter | Privacy Policy | Terms of Service