Fajar Jul
Fajar Jul

Reputation: 7

how to input date (using input Form date) to txt using PHP?

I want to ask how to input date with format YYYYMMDD to txt file using PHP? here my code, but I just can input it using text not as date form :

<a> From : </a>                        // to show date after input
<?php                                 // to show date after input
echo file_get_contents(from.txt" );  // to show date after input
?>                                  // to show date after input
<?php
    $file = "/var/www/html/from.txt";
    if(isset($_POST))
    {
    $postedHTML = $_POST['html'];
    file_put_contents($file, $postedHTML);
    }
?>
<form action="" method="post">
    <?php
    $content = file_get_contents($file);
    echo "<textarea name='html'>" . htmlspecialchars($content) . "</textarea>";
    ?>
    <input type="submit" value="Click to enter date" />
</form>

enter image description here

Upvotes: 0

Views: 418

Answers (2)

PHP Geek
PHP Geek

Reputation: 4033

try like this:

<form action="" method="post">
    <?php
    $content = file_get_contents($file);
   echo"<input type='date' name='date'>";
    ?>
    <input type="submit" value="Click to enter date" />
</form>

Upvotes: 0

Hưng ho&#224;ng
Hưng ho&#224;ng

Reputation: 356

you try this:

<form action="" method="post">
<?php
$date = htmlspecialchars($content)
$display_date= date("Y-m-d", strtotime($date));
echo "<input type='date' name='html' value ='" . $display_date . "'>";
?>
<input type="submit" value="Click to enter date" />
</form>

Upvotes: 1

Related Questions