I have a file named "test.html" with the code:
<html>
<body>
<p>welcome people<p>
<h1>nice</h1>
</body>
</html>
I need to create a copy of "test.html" and replace:
<p>welcome people<p>
and
<h1>nice</h1>
with another code.
So I need to create a form with 3 inputs:
<p>welcome people</p>
<h1>nice</h1>
I need following form
in a file named (control.html) with code :
<html>
<body>
<form method="get" action="process.php">
<input name="titlecopyfile">
<input name="code1">
<input name="code2">
<input type="submite">
</form>
</body>
</html>
I need the code for:
Here is the solution:
Test.html :
<html>
<body>
<p>welcome people<p>
<h1>nice</h1>
</body>
</html>
Control.html :
<html>
<body>
<form method="post" action="process.php">
<input name="titlecopyfile">
<input name="code1">
<input name="code2">
<input type="submit">
</form>
</body>
</html>
Process.php :
<?php
// Get all request parameters
$filename = $_REQUEST['titlecopyfile'];
$code1 = $_REQUEST['code1'];
$code2 = $_REQUEST['code2'];
// Read existing file content in a variable
$testHtml = file_get_contents('test.html');
// Replace desired strings with actual values
$testHtml = str_replace(array('<p>welcome people<p>', '<h1>nice</h1>'), array($code1, $code2), $testHtml);
// Write file on disk physically and save it as specified name
file_put_contents($filename, $testHtml);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments