I'm trying to edit a local .html file and the specific contents of that file with a PHP file on my localhost. I want to add forms where a user can input the information and the PHP file will replace the text / fill in the text on the HTML document with the user defined variables. Any suggestions?
I've already tried str_replace, file_get_contents and file_put_contents, but It's still not working. My local xampp server is running Apache 2.
$main = $_POST['value'];
echo $main;
The 'value' is from a HTML form, which I've tried using for getting user input.
function replace_string_in_file($filename, $string_to_replace, $replace_with){
$content=file_get_contents($filename);
$content_chunks=explode($string_to_replace, $content);
$content=implode($replace_with, $content_chunks);
file_put_contents($filename, $content);
}
$filename="alt.html";
$string_to_replace="yes";
$replace_with = "$main";
replace_string_in_file($filename, $string_to_replace, $replace_with)
Within the HTML file, there is some text I've set called 'yes'. I expected the output to change the text 'yes', to a defined user variable, but it won't change at all.
Below is my HTML text from the other document that I want to edit:
<div class="t m0 x7 h6 y9 ff2 fs6 fc0 sc0 ls0 ws0">Date of certification: <span class="_ _6"> </span><span class="ff1">17 June 2019</span></div>
The form data that the user inputs data into is below as well:
<form method="post" action="">
<input type="text" name="value">
<input type="
Also, just to be sure people know, the variable $replace_with = "$main";
is the form data in HTML. $main = $_POST['value'];
Thanks