我想用php exec函数中的两个变量"hour“和"mins”交换"30“和"16”。
$hour = 30;
$mins = 16;
exec('echo "30 16 * * * sudo /home/pi/raspberry-remote/./send 11010 1 1" | crontab -');
就这样改变了它:
exec('echo "$hour $mins * * * sudo /home/pi/raspberry-remote/./send 11010 1 1" | crontab -');
我怎么才能把这件事做好?谢谢
发布于 2014-06-19 03:47:31
未填充单引号字符串中的变量。试一试
exec('echo "'.$hour.' '.$mins.' * * * sudo /home/pi/raspberry-remote/./send 11010 1 1" | crontab -');
或
exec("echo \"$hour $mins * * * sudo /home/pi/raspberry-remote/./send 11010 1 1\" | crontab -");
发布于 2014-06-19 03:47:16
变量不是在单引号字符串中展开,而是在双引号字符串中展开。所以把你的引号转过来。
exec("echo '$hour $mins * * * sudo /home/pi/raspberry-remote/./send 11010 1 1' | crontab -");
发布于 2014-06-19 03:51:29
您可以使用concat字符串来完成此操作。
exec('echo "'.$hour.' ' .$mins.' * * * sudo /home/pi/raspberry-remote/./send 11010 1 1" | crontab -');exec('echo "$hour $mins * * * sudo /home/pi/raspberry-remote/./send 11010 1 1" | crontab -');
https://stackoverflow.com/questions/24305794
复制