php calling variable within complex quotations
-
15-11-2019 - |
Question
I'm trying to call a variable with a command that I need to send to windows CLI with no luck, if you could please help me out
$imagename = 123;
$test = ('C:\Windows\System32\cmd.exe /c "rundll32.exe C:\Windows\System32\shimgvw.dll,ImageView_PrintTo /pt "c:\pathtodirectory\$imagename" "photoprint""');
echo $test
$imagename
currently has a value of 123 but I am unable to call it within several quotations please help.
Thanks.
Solution
What about this one?
$imagename = 123;
$test = 'C:\Windows\System32\cmd.exe /c "rundll32.exe C:\Windows\System32\shimgvw.dll,ImageView_PrintTo /pt "c:\pathtodirectory\\' . $imagename . '" "photoprint"';
echo $test;
OTHER TIPS
Your initial string is within single quotes and PHP does not parse variables within single quoted strings.
Try either
$test = ("C:\Windows\System32\cmd.exe /c \"rundll32.exe C:\Windows\System32\shimgvw.dll,ImageView_PrintTo /pt \"c:\pathtodirectory\$imagename\" \"photoprint\"\"");
or
$test = ('C:\Windows\System32\cmd.exe /c "rundll32.exe C:\Windows\System32\shimgvw.dll,ImageView_PrintTo /pt ' . "\"c:\pathtodirectory\$imagename\"" . ' "photoprint""');