PHPで標準入力とファイル指定両方扱う
if ($argc<2) {
// 標準入力からデータを取得
$file='php://stdin';
} else {
// 最初のパラメータにファイルを指定した場合
$file=$argv[1];
}
main($file);
function main($file)
{
$fp=fopen($file,'r');
if (! $fp) {
echo "can't open ($file)\n";
return;
}
while(($ln=fgets($fp))!==false) {
$ln=chop($ln);
proc($ln);
}
}
複数の区切り文字を分割(multiexplode)
※ PHPドキュメントそのまま
function multiexplode ($delimiters,$string) {
$ready = str_replace($delimiters, $delimiters[0], $string);
$launch = explode($delimiters[0], $ready);
return $launch;
}
$val = multiexplode(array("=","[","]",",","(",")"), $line);