HTML + FORM + INPUT + REMPLACE code + PHP

Alilou Hassani

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:

  • input 1 : name of the copy (expemple test01.html)
  • input 2 : code which replace <p>welcome people</p>
  • input 3 : code which replace <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:

  • test.html
  • control.html
  • process.php
d.coder

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

HTML form with no input selector on code

From Dev

PHP script in FORM HTML <input>

From Dev

HTML/PHP Form - Input Type "Date"

From Dev

Sending hidden HTML form input to PHP

From Dev

Using PHP Variables as HTML Form Input Attributes

From Dev

PHP output from HTML input Form

From Dev

Why does PHP not GET the form input from this HTML form?

From Dev

HTML form input control before form action tot php

From Dev

PHP Help, inserting user input into html code

From Dev

Writing HTML / PHP Code inside an input/Textarea

From Dev

Get all input field names from an HTML form with code

From Dev

Python :- passing HTML form input to python code and execute it

From Dev

Populate form text input from PHP session - Simplify existing code

From Dev

How to remove $ and comma from form input using current php code?

From Dev

How to add PHP code inside input's value in a form

From Dev

How to connect html code to the php code "contact form"

From Dev

How to pass php array in input type hidden in html form

From Dev

PHP: How to escape HTML form input multidimensional keys

From Dev

How to send a PHP array via HTML form (using input tag)

From Dev

Program Calculator Using PHP for computation and a HTML input form

From Dev

Undefined value when calling an input from a HTML form from PHP

From Dev

Write HTML form input to .conf file using PHP

From Dev

html tables on form input

From Dev

Naming input of form html

From Dev

HTML form input width

From Dev

HTML input form css

From Dev

HTML form input

From Dev

Form input type php

From Dev

PHP if in form input