【发布时间】:2013-11-13 17:24:09
【问题描述】:
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
【问题讨论】: