Php substr_replace()不';在WHILE循环中无法按预期工作

Php substr_replace()不';在WHILE循环中无法按预期工作,php,mysql,substring,Php,Mysql,Substring,substr_replace()无法按预期工作,因为我处于while循环中 PHP $c= "2013-01-01 12:00:00"; $d= "2013-01-02 12:00:00"; $date_3 = date("Y-m-d g:i:s", strtotime("$c")); $date_4 = date("Y-m-d g:i:s", strtotime("$d")); $results = array($date_1); $i = $date_3; while ($i <=

substr_replace()无法按预期工作,因为我处于while循环中

PHP

$c= "2013-01-01 12:00:00";
$d= "2013-01-02 12:00:00";
$date_3 = date("Y-m-d g:i:s", strtotime("$c"));
$date_4 = date("Y-m-d g:i:s", strtotime("$d"));

$results = array($date_1);
$i = $date_3;
while ($i <= $date_4) {//here start the while look
$i = date("Y-m-d g:i:s", strtotime($i));
array_push($results, $i);
$k= $i . "\n";
$chunks = str_split($k, 19);
$nexstring = join('\')', $chunks);//2013-01-01 12:00:00') 2013-01-02 12:00:00') 2013-01-03 12:00:00')
$cane = implode(
', (\'',
str_split($nexstring, 21)//2013-01-01 12:00:00'), (' 2013-01-02 12:00:00'), (' 
);
echo substr_replace($cane, '(\'', 0, 0);//sub_string doesn't give my expected output
$i = date("Y-m-d g:i:s",strtotime("+1 day", strtotime($i)));
}//end while

我预计,$cane将

('2013-01-01 12:00:00'), (' 2013-01-02 12:00:00'), ('// my expected output
可能因为我在“while”中,它又增加了一个“(\”)

原始字符串

2013-01-01 12:00:00 2013-01-02 12:00:00 

据我所知,您来自
$date\u 1
$date\u 4
-不清楚-希望将2天添加为两个其他日期,格式为组合字符串,如
('2013-01-01 12:00:00'),('2013-01-02 12:00:00'),('2013-01-03 12:00:00'),
-同一时间,仅一天和两天之后。这是怎么回事:

$date = new DateTime($date_1);
$out = "('" . $date->format('Y-m-d H:i:s') . "')";
for ( $n = 1; $n < 3; $n ++ )
{
   $date->add(new DateInterval('P1D'));
   $out .= ", ('" . $date->format('Y-m-d H:i:s') . "')";
}
echo $out;
$date=新的日期时间($date\u 1);
$out=“(””$date->format('Y-m-dh:i:s')。“”);
对于($n=1;$n<3;$n++)
{
$date->add(新的日期间隔('P1D'));
$out.=”,(“$date->format('Y-m-dh:i:s')。”);
}
回音$out;

非常感谢您研究这段长代码,但这不是我想要的。我在循环中遇到substr\u replace的问题。
substr\u replace($cane),(\''',0,0);
语法错误:它不会以给定长度0(第四个参数)替换任何内容。它将在偏移量(0)处插入,与
$cane=”相同(\'.$cane
。因此,它可以按设计工作,并且问题不需要所有的东西。
2013-01-01 12:00:00 2013-01-02 12:00:00 
$date = new DateTime($date_1);
$out = "('" . $date->format('Y-m-d H:i:s') . "')";
for ( $n = 1; $n < 3; $n ++ )
{
   $date->add(new DateInterval('P1D'));
   $out .= ", ('" . $date->format('Y-m-d H:i:s') . "')";
}
echo $out;