How can I insert text in the middle of existing text with fwrite() function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I insert text in the middle of existing text with fwrite() function?

..

21st Aug 2018, 7:54 AM
Arrdas
3 Answers
+ 3
$doc = fopen("file.txt", "r+") ; $doclen = ftell($doc) ; fseek($doc, SEEK_SET, $doclen/2); fwrite($doc, "Hello") ; fclose() ; #Hope it Helps
23rd Aug 2018, 1:23 AM
Femi
Femi - avatar
+ 1
what about if i don't know how many bytes from beginning is position what i need... is any simple method to find text in the file? P.S. found somewhere that fseek not work with a and a+ mode, so we must use r or c, but what difference between them
21st Aug 2018, 5:31 PM
Arrdas
+ 1
Thanks Ishola. That is not exactly what I need, but you are right - that is answer to my question at the topic.
23rd Aug 2018, 7:45 AM
Arrdas