在perl和php中使用substr相同代码,不同结果。
php:
$addtime = "2009-04-13";
$datetime = "2008-12-31 12:00:00";
substr($datetime,0,10) = $addtime;
echo $datetime;
编译错误: Can't use function return value in write context
perl:
#!/usr/bin/perl -w
use strict;
my $addtime = "2009-04-13";
my $datetime = "2008-12-31 12:00:00";
substr($datetime,0,10) = $addtime;
print $datetime;
结果:2009-04-13 12:00:00
perl中的substr可以截取替换,php可以用substr_replace函数替换。
php的substr_replace函数使用:
$addtime = "2009-04-13";
$datetime = "2008-12-31 12:00:00";
$datetime = substr_replace($datetime,$addtime,0,10);
echo $datetime;