I have a small CSS file.
:root {
--header-bg:
#004d73;
--header-title-color:
#dbebfa;
}
I am trying to write a script that accepts an input value and overwrites a specific line in the CSS file with the new data. Here is what I have so far.
$path = 'custom-test.css';
if (isset($_POST['header-bg'])) {
$fh = fopen($path,"a+");
$string = $_POST['header-bg'];
fwrite($fh,$string,7); // Write information to the file
fclose($fh); // Close the file
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
This is working, except of course it simply appends the data to the end of the file.
I can't figure out if I need to specify what line to overwrite through fopen, fwrite, or if I need the script to open the entire file into an array (which is way beyond my rudimentary PHP skillset).
Again, my skills are quite limited. All tips are welcome, but suggestions that expand upon my existing code would be very helpful.
BTW without going into detail I cannot use a database entry for this.