解析错误:语法错误、意外的“createFromFormat”(T_STRING)、预期的变量(T_VARIABLE)或“$”

时间:2022-07-17 22:31:09

This is about room reservation site. I need to save the reservation dates in few rows by increase one day until the days i want to reserve. I'm new to php so i'm very thanksful to anyone who can simply explain me the problm. Here is the code.

这是关于订房地点的。我需要将预订日期保存在几行中,增加一天,直到我想预订的日期。我是php新手,所以我非常感谢任何能简单地向我解释这个问题的人。这是代码。

$today=date("Y/m/d");
$date = new DateTime::createFromFormat("l dS F Y", $in);

$con = mysql_connect("localhost","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("royal", $con);
{echo $i."<br>";
for ($y=1; $norooms>=$y; $y++)
    {
    echo "Day difference=".$len." No of rooms=".$norooms."<br>";
    $date = $date->format('d/m/Y');
    $sql="INSERT INTO singlerooms (Date,Ref_Date)VALUES ($date,$today)";
    mysql_query($sql,$con);
    }
}

3 个解决方案

#1


7  

You don't need the new keyword there. createFromFormat() is a static method in the DateTime class. It should be called as follows:

这里不需要新的关键字。createFromFormat()是DateTime类中的一个静态方法。它的名称应如下:

$date = DateTime::createFromFormat("l dS F Y", $in);

#2


1  

if you are using php5.3 then you should have this function available.

如果您正在使用php5.3,那么您应该可以使用这个函数。

Code snippet. Remove new keyword.

代码片段。删除新关键字。

<?php
$date = DateTime::createFromFormat('j-M-Y', '15-Feb-2009');
echo $date->format('Y-m-d');
?>

Your code: $date = DateTime::createFromFormat("l dS F Y", $in);

您的代码:$date = DateTime::createFromFormat(“ldsfy”,$in);

Docs Link: http://php.net/datetime.createfromformat

文档链接:http://php.net/datetime.createfromformat

#3


-1  

You can use this

你可以使用这个

$date = new DateTime;
$date1 = $date->createFromFormat("l dS F Y", $in);

#1


7  

You don't need the new keyword there. createFromFormat() is a static method in the DateTime class. It should be called as follows:

这里不需要新的关键字。createFromFormat()是DateTime类中的一个静态方法。它的名称应如下:

$date = DateTime::createFromFormat("l dS F Y", $in);

#2


1  

if you are using php5.3 then you should have this function available.

如果您正在使用php5.3,那么您应该可以使用这个函数。

Code snippet. Remove new keyword.

代码片段。删除新关键字。

<?php
$date = DateTime::createFromFormat('j-M-Y', '15-Feb-2009');
echo $date->format('Y-m-d');
?>

Your code: $date = DateTime::createFromFormat("l dS F Y", $in);

您的代码:$date = DateTime::createFromFormat(“ldsfy”,$in);

Docs Link: http://php.net/datetime.createfromformat

文档链接:http://php.net/datetime.createfromformat

#3


-1  

You can use this

你可以使用这个

$date = new DateTime;
$date1 = $date->createFromFormat("l dS F Y", $in);