I get the following error. tried for 3 days to understand it, but no success:
PHP Parse error: syntax error, unexpected '{' in
/home/jharvard/vhosts/pset8/import on line 13.
It's the very first curly brace. My code:
#!/usr/bin/env php
<?php
$sourcefile = $argv[1];
import($sourcefile);
/**
* fills database "places" with geo-data from a text-file
*/
function import($sourcefile) {
// file exists?
if (!file_exists($sourcefile) {
print("The source file doesn't exist!");
}
// file exists and readable?
if (!is_readable($sourcefile) {
print("The source file isn't readable (you may not have access to this file)!");
}
// open the source file
$handle = $fopen("($sourcefile)", "r");
// success?
if ($handle === false) {
print("Source file not opened");
}
// source file accessible: iterate through and fill table places
while (($places = fgetcsv($handle, 0, "\t")) {
$insert = query("INSERT INTO places
(country_code, postal_code, place_name, admin_name1, admin_code1,
admin_name2, admin_code2, admin_name3, admin_code3, latitude,
longitude, accuracy)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
$places[0], $places[1], $places[2], $places[3], $places[4],
$places[5], $places[6], $places[7], $places[8], $places[9],
$places[10], $places[11])
);
}
fclose($handle);
}