有没有一种 PHP 的方法可以实现 bash 大括号扩展?例如:
但这似乎不是正确的方法(并且可能在Windows服务器上无法工作)。
请注意,这仅适用于打印字符串的用例,而不涉及大括号扩展的其他功能,例如运行命令组相关的功能。
[chiliNUT@server ~]$ echo {hello,hi,hey}\ {friends,world},
hello friends, hello world, hi friends, hi world, hey friends, hey world,
something like
<?php
echo brace_expand("{hello,hi,hey} {friends,world}");
//hello friends, hello world, hi friends, hi world, hey friends, hey world,
目前我正在使用
<?php
echo shell_exec("echo {hello,hi,hey}\ {friends,world}");
但这似乎不是正确的方法(并且可能在Windows服务器上无法工作)。
请注意,这仅适用于打印字符串的用例,而不涉及大括号扩展的其他功能,例如运行命令组相关的功能。
shell_exec()
。如果您想在循环中执行此任务,可以使用popen
启动一个 shell,并重复使用已打开的 shell 执行每个扩展操作。 - hek2mgl