I want to only allow visitors to choose from certain dates, for example the next 20 days. So I have a form which looks like this.
<select name="data">
<?php
$day = date('d');
$i = 1;
while($i < 20) {
$i++;
$data = (date("d-M-Y",mktime(0,0,0,7,$day,2011)) . "<br />");
echo "<option value='".$data."'>".$data."</option>";
$day++;
}
?>
</select>
In the controller (I use Code Igniter), I can echo the date but I cannot make a timestamp out of the date.
$data = $this->input->post('data');
$timestamp = strtotime('$data')开发者_运维知识库;
echo $timestamp;
The echo $timestamp
doesn't work. It displays nothing.
My $date
is 23-08-2011
However, echo strtotime('23-08-2011');
works.
I even tried it outside of Code Igniter (1 form, 1 processformfile) and it still doesn't work.
Do you have any ideas why it doesn't work?
Thanks a lot.
Well, $timestamp=strtotime('$data');
wouldn't work because you're treating $data
as a literal string. Remove the quotes:
$timestamp=strtotime($data);
Also, you're setting $data
as a formatted string with a line break:
$data=(date("d-M-Y",mktime(0,0,0,7,$day,2011))."<br />");
Try:
$data=date("d-M-Y",mktime(0,0,0,7,$day,2011);
精彩评论