- 2025/11/17
- Category :
[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

ステップアップしていくブログです。
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
<?php
exec('ls .', $output);
foreach ($output as $file) {
exec('wc -m '.$file, $wc);
echo ($wc[0]."\n");
}
exec('ls .', $output);
$ php wc.php 8 a.txt 8 a.txt 8 a.txt 8 a.txt
<?php
exec('ls .', $output);
foreach ($output as $file) {
exec('wc -m '.$file, $wc);
echo ($file.':'.$wc[0]."\n");
}
$ php wc.php a.txt:8 a.txt b.txt:8 a.txt c.txt:8 a.txt wc.php:8 a.txt
<?php
exec('ls .', $output);
foreach ($output as $file) {
exec('wc -m '.$file, $wc);
var_dump($wc);
}
$ php wc.php
array(1) {
[0]=>
string(7) "8 a.txt"
}
array(2) {
[0]=>
string(7) "8 a.txt"
[1]=>
string(8) "12 b.txt"
}
array(3) {
[0]=>
string(7) "8 a.txt"
[1]=>
string(8) "12 b.txt"
[2]=>
string(7) "4 c.txt"
}
array(4) {
[0]=>
string(7) "8 a.txt"
[1]=>
string(8) "12 b.txt"
[2]=>
string(7) "4 c.txt"
[3]=>
string(10) "192 wc.php"
}
配列に既に何らかの要素が 含まれる場合は、exec() は配列の最後に追加されることに注意してください。関数が要素を追加することを望まないのなら、それが exec() に渡される前に、配列の unset() を呼び出してください。
<?php
exec('ls .', $output);
foreach ($output as $file) {
unset($wc);
exec('wc -m '.$file, $wc);
echo ($wc[0]."\n");
}
$ php wc.php 8 a.txt 12 b.txt 4 c.txt 190 wc.php