Php shell_exec,imagemagick转换不';我似乎不喜欢美元
这项工作:Php shell_exec,imagemagick转换不';我似乎不喜欢美元,php,imagemagick,Php,Imagemagick,这项工作: shell_exec('convert Q39.pdf Q39.png') 然而,这并不是: $id=39; shell_exec('convert Q$id.pdf Q$id.png') 在另一个shell_exec中,它使用另一个命令(pdflatex)工作。不知何故,$id被忽略,因此找不到该文件,因此执行以下操作: $id=39; shell_exec('convert Q39.pdf Q$id.png') 我得到了一个名为Q.png的正确文件 有没有办法解决这个问题 提前感
shell_exec('convert Q39.pdf Q39.png')代码>
然而,这并不是:
$id=39;
shell_exec('convert Q$id.pdf Q$id.png')代码>
在另一个shell_exec中,它使用另一个命令(pdflatex)工作。不知何故,$id被忽略,因此找不到该文件,因此执行以下操作:
$id=39;
shell_exec('convert Q39.pdf Q$id.png')代码>
我得到了一个名为Q.png的正确文件
有没有办法解决这个问题
提前感谢。要在字符串文本中使用变量,必须使用双引号:
$id = 39; shell_exec("convert Q$id.pdf Q$id.png");
或将它们连接起来:
$id = 39; shell_exec('convert Q'.$id.'.pdf Q'.$id.'.png');
我建议使用第二种方法,因为使用语法高亮显示时可读性更好
或者更好,确保它始终是十进制:
$id = 39; shell_exec(sprintf('convert Q%1$d.pdf Q%1$d.png', $id));
这还将显示用于生成命令的变量