summaryrefslogtreecommitdiff
blob: e1266d1331361e6b03f2e72d626703b96d459f75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
/**
 * tab2txt: Converts the original tabulated data file of ISO codes to a three
 * column text file (ISO 639-1, ISO 639-3, Natural Name).
 *
 * Usage: <tab file> | php tab2txt.php > codes.txt
 */

$dir = __DIR__;
$IP = "$dir/../..";
require_once "$IP/maintenance/commandLine.inc";

$fr = fopen( 'php://stdin', 'r' );
$fw = fopen( 'php://stdout', 'w' );

// Read and discard header line.
fgets( $fr );

while ( $line = fgets( $fr ) ) {
	$line = explode( "\t", $line );
	$iso1 = trim( $line[3] );
	if ( $iso1 === '' ) {
		$iso1 = '-';
	}
	$iso3 = trim( $line[0] );
	$name = $line[6];
	fwrite( $fw, "$iso1 $iso3 \"$name\"\n" );
}
fclose( $fr );
fclose( $fw );