html - explode the strings from the file in php -
as new php.i trying explode strings file.i want part of strings display in html fields. here complete code:-
<?php if(isset($_post["submit"])) { $lhs= array(); $rhs= array(); foreach($_post $key => $value){ if($key == "submit") continue; echo $key ."=". $value ; echo "<br>"; $lhs[]=$key; //first array left hand side $rhs[]=$value; //second array 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 output this
name=xyz phone=12334 course=bba array ( [0] => name [1] => xyz phone [2] => 12334 course [3] => bba )
now want display values
xyz 12334 bba
in respective html fields.and if edit values in file update in html fields when refresh/reload page. , not sure approach correct or not achieve requirement.
please or advice appreciated.thanks in advance.
$str=implode(",",$data); $str1=str_replace(" ",",",$str); $output_array=explode(",",$str1); print_r($output_array);
this give array
array ( [0] => name [1] => xyz [2] => phone [3] => 12334 [4] => course [5] => bba )
now can use array
further can make assocaitive array
$arr_values=array(); for($i=0;$i<sizeof($output_array);$i++) { $arr_values[$output_array[$i]] = $output_array[++$i]; } print_r($arr_values);
this give out put
array ( [name] => xyz [phone] => 12334 [course] => bba )
Comments
Post a Comment