summaryrefslogtreecommitdiff
blob: a1388fbd64395122f7d83e493e428c594b3fca32 (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
31
32
33
34
35
<?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 ( true ) {
	$line = fgets( $fr );
	if ( !$line ) {
		break;
	}

	$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 );