重写一个Bash脚本到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.