Is it possible to overwrite a certain part of a txt file in php?
Let's say we have a .txt file with the text "1234567890", is it possible to change the 1 to a 9 so it says "9234567890" without touching the remaining numbers?
To clarify, it should only change a part of the text file and not rewrite the entire thing. I'm only allowed to use php and html.
This can be a one-liner, but I'm breaking it up so it makes more sense. Further, this would be faster using exec with sed or awk, but this is just PHP here.
$string = file_get_contents("yourfile"); $string = str_replace('1','9',$string); file_put_contents("youfile", $string);