I'm new to php and need some help, I am trying to take the user input and format it so that the output shows the last day of the month. Here's what I have so far:
<?php
//form for user-input
echo "<form name='form' method='post' action='array.php'>";
echo "<p>Enter Date in ' Month/Day/Year ' format<p>";
echo "<input type='text' id='date-input' name='date-input' placeholder='Enter date' />";
echo "</form>";
//grab user-input
$input=$_POST["date-input"];
//output in correct format
echo $input->format("m/t/Y");
?>
When I have just echo input variable without the format function and date format then it displays what the user inputs, but how it's set right now; nothing displays and I get this line:
Fatal error: Call to a member function format() on string in C:\xampp\htdocs\php-sessions\session-3\array.php on line 190
Line 190 is my echo input line.
$inputis a string not an object. try usingecho $input;and if you want date you may need to convert the string to date. Take a look at strtotime