我应该如何搜索包含要修改的记录的基于行的文本文件?

My data is in a text file as follows:

ID: 12345
Name: Cem
Surname: Mehmet
Age: 19

ID: 22222
Name: Yasar
Surname: Gormez
Age: 25

...and so on.

I would like to search with ID and change other fields of the records such as age. How should I build up this record and modify?

<html> 
    <head> 
        <meta charset="utf-8" /> 
        <title>search</title> 
    </head> 
    <body> 
        <form method="POST"> 
            <input type="text" name="q" id="q"></input> 
            <button type="sumbit">ok</button> 
        </form> 

        <?php if($_POST){ 
            $file = 'search.txt'; 
            $find = $_POST['q']; 
            $contents = file_get_contents($file); 
            $pattern = preg_quote($find, '/'); 
            $pattern = "/^.*$pattern.*\$/m"; 
            if(preg_match_all($pattern, $contents, $matches)){ 
               echo implode("
", $matches[0]); 
            } 
            else{ 
               echo "error"; 
            }} ?> 
    </body> 
</html>

</div>