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>