P
P
pmccom2020-05-09 20:10:01
PHP
pmccom, 2020-05-09 20:10:01

How to write to the very beginning of a line in a text file in php?

How to write to the very beginning of a line in a text file in php?
I have a script but I don’t know how to write this code at the very beginning of the line in text form
I want to have a mini online store script I’m not ready yet I need to do
how to do it help by the way here is the php code:

<?php 
$buytext=$_POST['buytext'];
$datavnes=$_POST['datavnes'];
$datapost = $_POST['datapost']; 
$jur = $_POST['jur']; 
$summ = $_POST['summ'];
$numberpp = $_POST['numberpp'];
$org = $_POST['org'];
$notes = $_POST['notes'];
$man = $_POST['man'];
$file_change="\n $datavnes;$datapost;$jur;$summ;$numberpp;$org;$notes;$man;$buytext";
$file=fopen("db/items.txt", "a+");
fputs($file,$file_change."\r");
fclose($file);
#."\r\n");
?>
<form method="post">
Добавить<br/>
<input placeholder="Дата внес." type="text" name="datavnes" /><br/>
<input placeholder="Дата пост." type="text" name="datapost" /><br/> 
<input placeholder="Юр. лицо" type="text" name="jur" /><br/> 
<input placeholder="Сумма" type="text" name="summ" /><br/> 
<input placeholder="Номер п/п" type="text" name="numberpp" /><br/> 
<input placeholder="Организация" type="text" name="org" /><br/>
<input placeholder="Примечание" type="text" name="notes" /> <br/>
<input placeholder="Менеджер" type="text" name="man" /><br/> 
<textarea rows="1" cols="5" name="buytext">купить</textarea></p>
<input type="submit" name="btn" />
</form>
<html>
 <head>
  <title>добавить товар</title>
 </head>
 <body>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FanatPHP, 2020-05-09
@FanatPHP

Add to the end

F
FANTASANTA, 2020-05-10
@FANTASANTA

fopen() has all sorts of modes, you probably need "r+": More details in the documentation.
$handle = fopen("resource.txt", "r+");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question