Hi guys,
I have the following code
$PC = "F:\\QNAP NAS S2 BUP\\Instructions\\"".$year.""\\"".$folder0."\\"".$folder2."\\"".$code."\\"";
and keep getting
Parse error: syntax error, unexpected '\\' (T_NS_SEPARATOR) in /var/www/filerestore/index.php on line 59
what’s the best way to fix this so i can echo the details out.
I’m fine with the linux full path there but the windows one has thrown me a bit.
After $year. you have two “”, you only need 1 (plus you need to escape the \ so they render properly :D.
cheers @cpradio
i ended up just a moment ago fixing it doing
$PC = "F:\\QNAP NAS S2 BUP\\Instructions\\\\".$year."\\\\".$folder0."\\\\".$folder2."\\\\".$code."\\\\";
For ease of use and readability I prefer using single quotes and never ever to use the escape backslash:
// confusing readability
// $PC = "F:\\QNAP NAS S2 BUP\\Instructions\\"".$year.""\\"".$folder0."\\"".$folder2."\\"".$code."\\"";
$year = '$year';
$folder0 = '$folder0';
$folder2 = '$folder2';
$code = '$code';
// using escape backslash:
$PC = 'F:\\QNAP NAS S2 BUP\\Instructions' .'\\\\' .$year .'\\\\' .$folder0 .'\\\\' .$folder2 .'\\\\' .$code .'\\\\';
echo $PC .'<br />';
// renaming PHP predefined constant
defined('_DS_') ?: define('_DS_', DIRECTORY_SEPARATOR); // predefined constant
$PC = 'F:\\QNAP NAS S2 BUP\\Instructions' ._DS_ .$year ._DS_ .$folder0 ._DS_ .$folder2 ._DS_ .$code ._DS_;
echo $PC .'<br />';