static function geoPHP::detectFormat in geoPHP 7
Same name and namespace in other branches
- 8 geoPHP/geoPHP.inc \geoPHP::detectFormat()
2 calls to geoPHP::detectFormat()
- geoPHP::load in geoPHP/geoPHP.inc
- test_detection in geoPHP/tests/test.php
File
- geoPHP/geoPHP.inc, line 229
Class
- geoPHP
Code
static function detectFormat(&$input) {
$mem = fopen('php://memory', 'r+');
fwrite($mem, $input, 11);
fseek($mem, 0);
$bytes = unpack("c*", fread($mem, 11));
if (empty($bytes)) {
return FALSE;
}
if ($bytes[1] == 9 || $bytes[1] == 10 || $bytes[1] == 32) {
$ltinput = ltrim($input);
return geoPHP::detectFormat($ltinput);
}
if ($bytes[1] == 1) {
if ($bytes[5]) {
return 'ewkb';
}
else {
return 'wkb';
}
}
if ($bytes[1] == 48 && $bytes[2] == 49) {
if (strlen($input) >= 18) {
return 'ewkb:1';
}
}
if ($bytes[1] == 123) {
return 'json';
}
if ($bytes[1] == 83) {
return 'ewkt';
}
$wkt_chars = array(
80,
76,
77,
71,
);
if (in_array($bytes[1], $wkt_chars)) {
return 'wkt';
}
if ($bytes[1] == 60) {
$string = substr($input, 0, 256);
if (strpos($string, '<kml') !== FALSE) {
return 'kml';
}
if (strpos($string, '<coordinate') !== FALSE) {
return 'kml';
}
if (strpos($string, '<gpx') !== FALSE) {
return 'gpx';
}
if (strpos($string, '<georss') !== FALSE) {
return 'georss';
}
if (strpos($string, '<rss') !== FALSE) {
return 'georss';
}
if (strpos($string, '<feed') !== FALSE) {
return 'georss';
}
}
fseek($mem, 0);
$string = trim(fread($mem, 8));
preg_match('/[a-z0-9]+/', $string, $matches);
if ($matches[0] == $string) {
return 'geohash';
}
return FALSE;
}