开发者

Rewrite a Bash script to php?

开发者 https://www.devze.com 2023-01-30 06:06 出处:网络
how would I rewrite this as a php script. also if anyone knows of开发者_如何学编程 a better way other than LAME please let me know.

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

精彩评论

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