ghurty Posted January 25, 2010 Share Posted January 25, 2010 I have the following script that works perfectly. The problem is when I substitute a variable it stops working: #!/usr/bin/php -q <?php $origdirectory= '/temp/0125/; $destdirectory='/destination/'; if(is_dir($origdirectory)) { $dh=opendir($origdirectory); $ctr=0; while($ctr<15 && $file=readdir($dh)) { if(is_file($origdirectory.$file)) { rename($origdirectory.$file,$destdirectory.$file); $ctr++; } } closedir($dh); if(!$ctr) rmdir($origdirectory); } ?> But when I try to change to: $temp = date(md); $origdirectory= '/temp/$temp/'; It stops working. I am using 0125 in this example, because it is todays date. Thanks Link to comment https://forums.phpfreaks.com/topic/189789-script-stops-working-when-substitue-variable-for-constant/ Share on other sites More sharing options...
jl5501 Posted January 25, 2010 Share Posted January 25, 2010 variables are not evaluated inside single quotes. Try $origdirectory= "/temp/$temp/"; Link to comment https://forums.phpfreaks.com/topic/189789-script-stops-working-when-substitue-variable-for-constant/#findComment-1001555 Share on other sites More sharing options...
ghurty Posted January 25, 2010 Author Share Posted January 25, 2010 It worked. Thanks Link to comment https://forums.phpfreaks.com/topic/189789-script-stops-working-when-substitue-variable-for-constant/#findComment-1001557 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.