在php中爆炸文件中的字符串

As i am new to the PHP.I am trying to explode the strings from the file.I want only some part of the strings to display in the html fields. So here is my complete code:-

<?php 
 if(isset($_POST["Submit"]))
{
    $lhs= array();
    $rhs= array();
    foreach($_POST as $key => $value){
        if($key == "Submit") continue;
        echo $key ."=". $value ;
        echo "<br>";
        $lhs[]=$key; //first array for left hand side 
        $rhs[]=$value; //second array for right hand side
        }
    
    file_put_contents("file2.txt", implode(PHP_EOL, array_map(function($v1, $v2)
    {
      return "$v1=$v2";
    },$lhs, $rhs)));
}
$file_contents=file_get_contents("file2.txt");
$data=explode("=" ,$file_contents);
print_r($data);
?>

    <form name="form1" method="post" action="">
    Name: <input type="text" name="name" value="<?php echo "$data[0]";?>"><br>
    Phone No: <input type="text" name="phone" /><br/>
    Course:<input type="text" name="course" /> <br />
    <input type="submit" name="Submit" value="Sign Up">
    </form> 
    

And the output would be like this

name=xyz
phone=12334
course=bba
Array ( [0] => name [1] => xyz phone [2] => 12334 course [3] => bba )

Now i want to display only values like

 xyz
 12334
 bba

In the respective html fields.And if i edit some values in file that also as to update in the html fields when i refresh/reload the page. And i am not sure this approach is correct or not to achieve my requirement.

Please any help or advice that will be appreciated.Thanks in advance.

</div>
$str=implode(",",$data);

$str1=str_replace(" ",",",$str);
$output_array=explode(",",$str1);
print_r($output_array);

This will give you array like this

Array
(
    [0] => name
    [1] => xyz
    [2] => phone
    [3] => 12334
    [4] => course
    [5] => bba
)

Now You Can use this array

Further You can make it Assocaitive Array Like this

$arr_values=array();
for($i=0;$i<sizeof($output_array);$i++)
{
$arr_values[$output_array[$i]] = $output_array[++$i];
}
print_r($arr_values); 

this will Give you out put like this

Array
(
    [name] => xyz
    [phone] => 12334
    [course] => bba
)

PHP_EOL = PHP End Of Line, same as or . You should use tab or some spaces.

implode('\t', array_map(function($v1, $v2))
> $str = "Hello world. It's a beautiful day."; $data= explode(" ",$str);
> 
> echo $data[0];  //hello echo $data[1];  //world.