开发者

Rewrite a Bash script to php?

how would I rewrite this as a php script. also if anyone knows of开发者_如何学编程 a better way other than LAME please let me know.

for i in *.wav; do
    lame -h -b 192 "$i" "${i%.wav}.mp3"
done


The straightforward rewrite would be:

<?php
foreach(glob('*.wav') as $i){
   exec('lame -h -b 192 ' . escapeshellarg($i) . ' ' . escape_shellarg(basename($i, '.wav') . '.mp3'));
}

Of course, it offers no advantage over your shell script ;-)

Edit: I'm not proficient with bash but I suspect ${i%.wav} may remove the .wav suffix; I've changed the PHP code accordingly.


You could use glob.

foreach (glob("*.wav") as $filename) {
..code ..
}


You'd need to execute the lame command in the shell anyway, so there is no use for this. If you need to kick the processing of from php, just execute the whole script from php.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜