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
,其中
$nexstring = 2013-01-01 12:00:00'), (' 2013-01-02 12:00:00'), ('
和
$cane=('2013-01-01 12:00:00'), (' ('2013-01-02 12:00:00'), ('//1 more parenthesis added to the second date.
我期待 $ 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
答案 0 :(得分:0)
据我所知,您来自$date_1
或$date_4
- 不清楚 - 并希望将其他日期添加2天,并将其组合为{{ {1}} - 同一时间,仅仅一两天。那怎么样:
('2013-01-01 12:00:00'), ('2013-01-02 12:00:00'), ('2013-01-03 12:00:00')