PHP parsing a file into array - php

I'm trying to figure out what I'm doing that gives me the wrong result.
I have a file composed this way:
2017/05/02 BA 86 23 39 89 5
2017/05/02 CA 23 4 14 86 5
2017/05/02 FI 71 26 19 15 6
2017/05/02 GE 69 5 16 58 83
2017/05/02 MI 19 45 4 16 68
2017/05/02 NA 6 16 75 78 89
2017/05/02 PA 67 83 21 5 1
2017/05/02 RM 51 79 12 47 19
2017/05/02 RN 27 83 41 37 23
2017/05/02 TO 44 17 60 31 53
2017/05/02 VE 89 32 48 71 57
2017/05/04 BA 61 70 47 71 75
2017/05/04 CA 26 44 16 77 55
2017/05/04 FI 3 11 37 38 18
2017/05/04 GE 70 14 75 86 55
2017/05/04 MI 71 53 39 6 30
2017/05/04 NA 73 20 12 13 54
2017/05/04 PA 37 49 33 80 61
2017/05/04 RM 39 60 75 32 2
2017/05/04 RN 40 78 43 75 55
2017/05/04 TO 24 87 52 90 16
2017/05/04 VE 14 54 25 61 63
2017/05/06 BA 15 31 20 78 66
2017/05/06 CA 84 33 47 9 45
2017/05/06 FI 17 48 33 49 20
2017/05/06 GE 16 51 62 21 72
2017/05/06 MI 12 83 64 62 2
2017/05/06 NA 15 80 52 5 89
2017/05/06 PA 2 33 65 72 61
2017/05/06 RM 29 49 13 70 83
2017/05/06 RN 30 81 55 37 41
As you can see this is formatted this way:
DATE(tab)LETTERS(tab)N1(tab)N2(tab)N3(tab)N4(tab)N5(tab)
The second line has the same date, and changes LETTERS and N_.
I need to insert this file into a DB but this has to have one line for every date, like so:
Date |BA1|BA2|BA3|BA4|BA5|CA1|CA2|CA3|CA4|CA5|FI1|FI2|FI3|FI4|FI5|
-----------------------------------------------------------------
2017/05/02| 86 | 23| 39| 89|5 |23 | 4 | 14|86 |5.....
-----------------------------------------------------------------
2017/05/04|61 |70 |47 |71 |75 |26 |44 |16 |77 |55...
Why my code is not working?
public function caricaStorico(){
$this->load->helper('file');
$storico = read_file(base_url("storico.txt"));
$splitter = explode("\n", $storico);
$data_estr = "-";
$insert = [];
$arr_key = 0;
echo "<pre>";
foreach ($splitter as $key => $value) {
$dati = explode("\t", $value);
if(count($dati)>1) {
$data_estr = $dati[0];
$ruota = $dati[1];
$n1 = $dati[2];
$n2 = $dati[3];
$n3 = $dati[4];
$n4 = $dati[5];
$n5 = $dati[6];
switch ($ruota) {
case 'BA':
array_push($insert, ["data_estrazione" => $data_estr, "BA1" => $n1, 'BA2' => $n2, "BA3" => $n3, "BA4" => $n4, "BA5" => $n5]);
break;
case 'FI':
$insert[$arr_key] += ["FI1" => $n1, 'FI2' => $n2, "FI3" => $n3, "FI4" => $n4, "FI5" => $n5];
break;
case 'MI':
$insert[$arr_key] += ["MI1" => $n1, 'MI2' => $n2, "MI3" => $n3, "MI4" => $n4, "MI5" => $n5];
break;
case 'NA':
$insert[$arr_key] += ["NA1" => $n1, 'NA2' => $n2, "NA3" => $n3, "NA4" => $n4, "NA5" => $n5];
break;
case 'PA':
$insert[$arr_key] += ["PA1" => $n1, 'PA2' => $n2, "PA3" => $n3, "PA4" => $n4, "PA5" => $n5];
break;
case 'RM':
$insert[$arr_key] += ["RM1" => $n1, 'RM2' => $n2, "RM3" => $n3, "RM4" => $n4, "RM5" => $n5];
break;
case 'TO':
$insert[$arr_key] += ["TO1" => $n1, 'TO2' => $n2, "TO3" => $n3, "TO4" => $n4, "TO5" => $n5];
break;
case 'VE':
$insert[$arr_key] += ["VE1" => $n1, 'VE2' => $n2, "VE3" => $n3, "VE4" => $n4, "VE5" => $n5];
break;
case 'RN':
$insert[$arr_key] += ["NZ1" => $n1, 'NZ2' => $n2, "NZ3" => $n3, "NZ4" => $n4, "NZ5" => $n5];
break;
}
}
$arr_key = $arr_key+1;
}
print_r($insert);
echo "</pre>";
}
If I remove the $input[$arr_key] and I do $input[0] I get the right result only on the first array while the others are only containing the BA numbers, as you can see:
Array
(
[0] => Array
(
[data_estrazione] => 1939/01/07
[BA1] => 58
[BA2] => 22
[BA3] => 47
[BA4] => 49
[BA5] => 69
[FI1] => 27
[FI2] => 57
[FI3] => 81
[FI4] => 43
[FI5] => 61
[MI1] => 40
[MI2] => 38
[MI3] => 57
[MI4] => 67
[MI5] => 7
[NA1] => 85
[NA2] => 44
[NA3] => 48
[NA4] => 88
[NA5] => 55
[PA1] => 73
[PA2] => 80
[PA3] => 39
[PA4] => 38
[PA5] => 57
[RM1] => 73
[RM2] => 24
[RM3] => 4
[RM4] => 39
[RM5] => 22
[TO1] => 19
[TO2] => 43
[TO3] => 10
[TO4] => 31
[TO5] => 27
[VE1] => 9
[VE2] => 43
[VE3] => 61
[VE4] => 14
[VE5] => 75
[NZ1] => 72
[NZ2] => 12
[NZ3] => 42
[NZ4] => 57
[NZ5] => 31
)
[1] => Array
(
[data_estrazione] => 1939/01/14
[BA1] => 18
[BA2] => 77
[BA3] => 33
[BA4] => 62
[BA5] => 19
)
[2] => Array
(
[data_estrazione] => 1939/01/21
[BA1] => 68
[BA2] => 65
[BA3] => 41
[BA4] => 28
[BA5] => 67
)
[3] => Array
(
[data_estrazione] => 1939/01/28
[BA1] => 76
[BA2] => 55
[BA3] => 48
[BA4] => 85
[BA5] => 71
)
[4] => Array
(
[data_estrazione] => 1939/02/04
[BA1] => 70
[BA2] => 2
[BA3] => 20
[BA4] => 85
[BA5] => 75
)
[5] => Array
(
[data_estrazione] => 1939/02/11
[BA1] => 82
[BA2] => 81
[BA3] => 16
[BA4] => 52
[BA5] => 77
)

You can achive this via using date as a key of array check this out:
I used string variable to demonstrate your case so you can change storico variable as you wish.
<?php
function caricaStorico(){
$storico = '2017/05/02 BA 86 23 39 89 5, 2017/05/02 CA 23 4 14 86 5, 2017/05/03 BA 86 23 39 89 5, 2017/05/03 CA 23 4 14 86 5';
$splitter = explode(",", $storico);
$data_estr = "-";
$insert = [];
echo "<pre>";
foreach ($splitter as $key => $value) {
$dati = explode(" ", $value);
if(count($dati)>1) {
$data_estr = trim($dati[0]);
$ruota = $dati[1];
$n1 = $dati[2];
$n2 = $dati[3];
$n3 = $dati[4];
$n4 = $dati[5];
$n5 = $dati[6];
if(isset($insert[$data_estr]) && is_array($insert[$data_estr]) )
$insert[$data_estr] += [ "data_estrazione" => $data_estr, $ruota."1" => $n1, $ruota."2" => $n2, $ruota."3" => $n3, $ruota."4" => $n4, $ruota."5" => $n5 ];
else
$insert[$data_estr] = array("data_estrazione" => $data_estr, $ruota."1" => $n1, $ruota."2" => $n2, $ruota."3" => $n3, $ruota."4" => $n4, $ruota."5" => $n5 );
}
}
print_r($insert);
echo "</pre>";
}
caricaStorico();
?>
output to this code:
Array
(
[2017/05/02] => Array
(
[data_estrazione] => 2017/05/02
[BA1] => 86
[BA2] => 23
[BA3] => 39
[BA4] => 89
[BA5] => 5
[CA1] => 23
[CA2] => 4
[CA3] => 14
[CA4] => 86
[CA5] => 5
)
[2017/05/03] => Array
(
[data_estrazione] => 2017/05/03
[BA1] => 86
[BA2] => 23
[BA3] => 39
[BA4] => 89
[BA5] => 5
[CA1] => 23
[CA2] => 4
[CA3] => 14
[CA4] => 86
[CA5] => 5
)
)

Related

Laravel: Count integer value based on week of the month

I'm trying to count integer value from JSON: https://pomber.github.io/covid19/timeseries.json and got what I expected.
{
"date": [
"22 Jan",
"23 Jan",
"24 Jan",
"25 Jan",
....
],
"total_confirmed": [
555,
653,
941,
1434,
....
],
"total_deaths": [
17,
18,
26,
42,
....
],
"total_recovered": [
28,
30,
36,
39,
....
],
"max_value_of_total_confirmed": 272166
}
Here's my controller:
$client = new Client();$request = $client->get('https://pomber.github.io/covid19/timeseries.json');
$response = $request->getBody()->getContents();
$posts_dates = json_decode($response, true);
$confirmed_array = array();
$deaths_array = array();
$recovered_array = array();
if ( ! empty( $posts_dates ) ) {
foreach ( $posts_dates as $country => $data ) {
foreach ( $data as $dataKey => $dateData ) {
$date = new \DateTime( $dateData['date'] );
$day = $date->format( 'd M' );
if ( !isset($confirmed_array[$day]) ) {
$confirmed_array[$day] = 0;
}
$confirmed_array[$day] += $dateData['confirmed'];
}
foreach ( $data as $dataKey => $dateData ) {
$date = new \DateTime( $dateData['date'] );
$day = $date->format( 'd M' );
if ( !isset($deaths_array[$day]) ) {
$deaths_array[$day] = 0;
}
$deaths_array[$day] += $dateData['deaths'];
}
foreach ( $data as $dataKey => $dateData ) {
$date = new \DateTime( $dateData['date'] );
$day = $date->format( 'd M' );
if ( !isset($recovered_array[$day]) ) {
$recovered_array[$day] = 0;
}
$recovered_array[$day] += $dateData['recovered'];
}
}
}
$output = [
"date" => array_keys($confirmed_array),
"total_confirmed" => array_values($confirmed_array),
"total_deaths" => array_values($deaths_array),
"total_recovered" => array_values($recovered_array),
"max_value_of_total_confirmed" => max($confirmed_array)
];
return $output;
What I'm trying to get is grouping those data not by date, but by week of the month (W3 Jan, W4 Jan, W1 Feb, W2 Feb, etc). Any help would be appreciated :)
Thank you.
I would recommend using collection. You can easily manage using the methods provided by Laravel.
Group By Day
$client = new Client();
$request = $client->get('https://pomber.github.io/covid19/timeseries.json');
$response = $request->getBody()->getContents();
$posts_dates = json_decode($response, true);
/****** Here we go ******/
$posts_dates = collect($posts_dates)
->flatten(1)
->groupBy('date')
->map(function ($item, $key) {
$item = collect($item);
$date = \Carbon\Carbon::parse($key);
$key = 'W' . $date->weekOfMonth . $date->format(' M');
return [
'date' => $key,
'total_confirmed' => $item->sum('confirmed'),
'total_deaths' => $item->sum('deaths'),
'total_recovered' => $item->sum('recovered'),
];
})
->groupBy(function ($item, $key) {
return collect($item)->keys()->all();
})
->map(function ($item, $key) {
return $item->map(function ($item) use ($key) {
return $item[$key];
});
});
$posts_dates->put('max_value_of_total_confirmed', $posts_dates['total_confirmed']->max());
dd($posts_dates->toArray());
Result
array:5 [
"date" => array:59 [
0 => "W4 Jan"
1 => "W4 Jan"
2 => "W4 Jan"
3 => "W4 Jan"
4 => "W4 Jan"
5 => "W4 Jan"
6 => "W4 Jan"
7 => "W5 Jan"
8 => "W5 Jan"
9 => "W5 Jan"
10 => "W1 Feb"
11 => "W1 Feb"
12 => "W1 Feb"
13 => "W1 Feb"
14 => "W1 Feb"
15 => "W1 Feb"
16 => "W1 Feb"
17 => "W2 Feb"
18 => "W2 Feb"
19 => "W2 Feb"
20 => "W2 Feb"
21 => "W2 Feb"
22 => "W2 Feb"
23 => "W2 Feb"
24 => "W3 Feb"
25 => "W3 Feb"
26 => "W3 Feb"
27 => "W3 Feb"
28 => "W3 Feb"
29 => "W3 Feb"
30 => "W3 Feb"
31 => "W4 Feb"
32 => "W4 Feb"
33 => "W4 Feb"
34 => "W4 Feb"
35 => "W4 Feb"
36 => "W4 Feb"
37 => "W4 Feb"
38 => "W5 Feb"
39 => "W1 Mar"
40 => "W1 Mar"
41 => "W1 Mar"
42 => "W1 Mar"
43 => "W1 Mar"
44 => "W1 Mar"
45 => "W1 Mar"
46 => "W2 Mar"
47 => "W2 Mar"
48 => "W2 Mar"
49 => "W2 Mar"
50 => "W2 Mar"
51 => "W2 Mar"
52 => "W2 Mar"
53 => "W3 Mar"
54 => "W3 Mar"
55 => "W3 Mar"
56 => "W3 Mar"
57 => "W3 Mar"
58 => "W3 Mar"
]
"total_confirmed" => array:59 [
0 => 555
1 => 653
2 => 941
3 => 1434
4 => 2118
5 => 2927
6 => 5578
7 => 6166
8 => 8234
9 => 9927
10 => 12038
11 => 16787
12 => 19881
13 => 23892
14 => 27635
15 => 30817
16 => 34391
17 => 37120
18 => 40150
19 => 42762
20 => 44802
21 => 45221
22 => 60368
23 => 66885
24 => 69030
25 => 71224
26 => 73258
27 => 75136
28 => 75639
29 => 76197
30 => 76823
31 => 78579
32 => 78965
33 => 79568
34 => 80413
35 => 81395
36 => 82754
37 => 84120
38 => 86011
39 => 88369
40 => 90306
41 => 92840
42 => 95120
43 => 97882
44 => 101784
45 => 105821
46 => 109795
47 => 113561
48 => 118592
49 => 125865
50 => 128343
51 => 145193
52 => 156094
53 => 167446
54 => 181527
55 => 197142
56 => 214910
57 => 242708
58 => 272166
]
"total_deaths" => array:59 [
0 => 17
1 => 18
2 => 26
3 => 42
4 => 56
5 => 82
6 => 131
7 => 133
8 => 171
9 => 213
10 => 259
11 => 362
12 => 426
13 => 492
14 => 564
15 => 634
16 => 719
17 => 806
18 => 906
19 => 1013
20 => 1113
21 => 1118
22 => 1371
23 => 1523
24 => 1666
25 => 1770
26 => 1868
27 => 2007
28 => 2122
29 => 2247
30 => 2251
31 => 2458
32 => 2469
33 => 2629
34 => 2708
35 => 2770
36 => 2814
37 => 2872
38 => 2941
39 => 2996
40 => 3085
41 => 3160
42 => 3254
43 => 3348
44 => 3460
45 => 3558
46 => 3802
47 => 3988
48 => 4262
49 => 4615
50 => 4720
51 => 5404
52 => 5819
53 => 6440
54 => 7126
55 => 7905
56 => 8733
57 => 9867
58 => 11299
]
"total_recovered" => array:59 [
0 => 28
1 => 30
2 => 36
3 => 39
4 => 52
5 => 61
6 => 107
7 => 126
8 => 143
9 => 222
10 => 284
11 => 472
12 => 623
13 => 852
14 => 1124
15 => 1487
16 => 2011
17 => 2616
18 => 3244
19 => 3946
20 => 4683
21 => 5150
22 => 6295
23 => 8058
24 => 9395
25 => 10865
26 => 12583
27 => 14352
28 => 16121
29 => 18177
30 => 18890
31 => 22886
32 => 23394
33 => 25227
34 => 27905
35 => 30384
36 => 33277
37 => 36711
38 => 39782
39 => 42716
40 => 45602
41 => 48228
42 => 51170
43 => 53796
44 => 55865
45 => 58358
46 => 60694
47 => 62494
48 => 64404
49 => 67003
50 => 68324
51 => 70251
52 => 72624
53 => 76034
54 => 78088
55 => 80840
56 => 83207
57 => 84854
58 => 87256
]
"max_value_of_total_confirmed" => 272166
]
Group By Week
$client = new Client();
$request = $client->get('https://pomber.github.io/covid19/timeseries.json');
$response = $request->getBody()->getContents();
$posts_dates = json_decode($response, true);
/****** Here we go ******/
$posts_dates = collect($posts_dates)
->flatten(1)
->map(function ($item) {
$date = \Carbon\Carbon::parse($item['date']);
$item['week'] = 'W' . $date->weekOfMonth . $date->format(' M');
return $item;
})
->groupBy('week')
->map(function ($item, $key) {
$item = collect($item);
return [
'date' => $key,
'total_confirmed' => $item->sum('confirmed'),
'total_deaths' => $item->sum('deaths'),
'total_recovered' => $item->sum('recovered'),
];
})
->groupBy(function ($item, $key) {
return collect($item)->keys()->all();
})
->map(function ($item, $key) {
return $item->map(function ($item) use ($key) {
return $item[$key];
});
});
$posts_dates->put('max_value_of_total_confirmed', $posts_dates['total_confirmed']->max());
dd($posts_dates->toArray());
Result
array:5 [
"date" => array:10 [
0 => "W4 Jan"
1 => "W5 Jan"
2 => "W1 Feb"
3 => "W2 Feb"
4 => "W3 Feb"
5 => "W4 Feb"
6 => "W5 Feb"
7 => "W1 Mar"
8 => "W2 Mar"
9 => "W3 Mar"
]
"total_confirmed" => array:10 [
0 => 14206
1 => 24327
2 => 165441
3 => 337308
4 => 517307
5 => 565794
6 => 86011
7 => 672122
8 => 897443
9 => 1275899
]
"total_deaths" => array:10 [
0 => 372
1 => 517
2 => 3456
3 => 7850
4 => 13931
5 => 18720
6 => 2941
7 => 22861
8 => 32610
9 => 51370
]
"total_recovered" => array:10 [
0 => 353
1 => 491
2 => 6853
3 => 33992
4 => 100383
5 => 199784
6 => 39782
7 => 355735
8 => 465794
9 => 490279
]
"max_value_of_total_confirmed" => 1275899
]

php construct associative array key value incremental loop

Below is what I am trying to accomplish
Array
(
[0.94] => 35
[0.93] => 36
[0.92] => 37
[0.91] => 38
.
.
.
[0.50] => 79
)
instead of building
$arrayName1 = array('0.94' => '35',
'0.93' => '36',
'0.92' => '37',
'0.91' => '38',
'0.50' => '79'
);
I'd like to know if there's a way to add loop to it to simplify process. Anyone?
With range() and array_combine() functions:
$result = array_combine(range(0.94, 0.5, -0.01), range(35, 79));
The $result contains:
Array
(
[0.94] => 35
[0.93] => 36
[0.92] => 37
[0.91] => 38
[0.9] => 39
[0.89] => 40
[0.88] => 41
[0.87] => 42
[0.86] => 43
[0.85] => 44
[0.84] => 45
[0.83] => 46
[0.82] => 47
[0.81] => 48
[0.8] => 49
[0.79] => 50
[0.78] => 51
[0.77] => 52
[0.76] => 53
[0.75] => 54
[0.74] => 55
[0.73] => 56
[0.72] => 57
[0.71] => 58
[0.7] => 59
[0.69] => 60
[0.68] => 61
[0.67] => 62
[0.66] => 63
[0.65] => 64
[0.64] => 65
[0.63] => 66
[0.62] => 67
[0.61] => 68
[0.6] => 69
[0.59] => 70
[0.58] => 71
[0.57] => 72
[0.56] => 73
[0.55] => 74
[0.54] => 75
[0.53] => 76
[0.52] => 77
[0.51] => 78
[0.5] => 79
)
You could simply loop.
$data = array();
$i = 0.94;
$j = 35;
while($i > 0.50){
$data[(string)$i] = $j;
$i -= 0.01;
$j++;
}
var_dump($data);

Symfony2 weird issue with for loop or me :)

I experience a weird issue with for loop I mean I have associative array with makes:
$makes = array(0 => '9FF',
1 => 'AC',
2 => 'AMG',
3 => 'Alfa Romeo',
4 => 'Alpina',
5 => 'Ariel',
6 => 'Ascari',
7 => 'Aston Martin',
8 => 'Audi',
9 => 'B Engineering',
10 => 'BAC',
11 => 'BMW',
12 => 'Beck',
13 => 'Bentley',
14 => 'Bertone',
15 => 'Bizzarrini',
16 => 'Brabus',
17 => 'Bristol',
18 => 'Brooke',
19 => 'Bugatti',
20 => 'Buick',
21 => 'Cadillac',
22 => 'Callaway',
23 => 'Caparo',
24 => 'Caterham',
25 => 'Chevrolet',
26 => 'Chrysler',
27 => 'Citroen',
28 => 'Cizeta Moroder',
29 => 'Connaught',
30 => 'Covini',
31 => 'Dauer',
32 => 'David Brown',
33 => 'Dax',
34 => 'De Lorean',
35 => 'De Tomaso',
36 => 'Dodge',
37 => 'Dome',
38 => 'ES Motorsports',
39 => 'Elfin',
40 => 'Ferrari',
41 => 'Fiat',
42 => 'Fioravanti',
43 => 'Fisker',
44 => 'Ford',
45 => 'GM',
46 => 'GTA',
47 => 'Gemballa',
48 => 'Ghia',
49 => 'Ginetta',
50 => 'Giugiaro',
51 => 'Grinnall',
52 => 'Gumpert',
53 => 'Hennessey',
54 => 'Heuliez',
55 => 'Honda',
56 => 'Invicta',
57 => 'Isdera',
58 => 'Iso',
59 => 'Ital Design',
60 => 'Jaguar',
61 => 'Jeep',
62 => 'Jensen',
63 => 'Joss',
64 => 'KTM',
65 => 'Keio University',
66 => 'Koenig',
67 => 'Koenigsegg',
68 => 'Lamborghini',
69 => 'Lancia',
70 => 'Land Rover',
71 => 'LeBlanc',
72 => 'Leading Edge',
73 => 'Lexus',
74 => 'Light Car Company',
75 => 'Lingenfelter',
76 => 'Lister',
77 => 'Lotec',
78 => 'Lotus',
79 => 'MB Roadcars',
80 => 'MG',
81 => 'Marcos',
82 => 'Maserati',
83 => 'Maybach',
84 => 'Mazda',
85 => 'McLaren',
86 => 'Melling',
87 => 'Mercedes',
88 => 'Mitsubishi',
89 => 'Monteverdi',
90 => 'Morgan',
91 => 'Mosler',
92 => 'Nissan',
93 => 'Noble',
94 => 'Oldsmobile',
95 => 'Pagani',
96 => 'Palmer',
97 => 'Panoz',
98 => 'Panther',
99 => 'Peugeot',
100 => 'Pininfarina',
101 => 'Plymouth',
102 => 'Pontiac',
103 => 'Porsche',
104 => 'Prodrive',
105 => 'Radical',
106 => 'Renault',
107 => 'Rimac',
108 => 'Rolls Royce',
109 => 'Roush',
110 => 'Ruf',
111 => 'SCG',
112 => 'SSC',
113 => 'Saab',
114 => 'Saleen',
115 => 'Sbarro',
116 => 'Schuppan',
117 => 'Sin',
118 => 'Spectre',
119 => 'Spyker',
120 => 'Stealth',
121 => 'Strathcarron',
122 => 'Studiotorino',
123 => 'Subaru',
124 => 'Superformance',
125 => 'TVR',
126 => 'Techart',
127 => 'Tesla',
128 => 'Tiger',
129 => 'Toroidion',
130 => 'Toyota',
131 => 'Tramontana',
132 => 'Trident',
133 => 'UVA',
134 => 'Ultima',
135 => 'Vauxhall',
136 => 'Vector',
137 => 'Vemac',
138 => 'Venturi',
139 => 'Veritas',
140 => 'Volkswagen',
141 => 'Volvo',
142 => 'Westfield',
143 => 'Wiesmann',
144 => 'Wolfrace',
145 => 'Yamaha',
146 => 'Zagato',
147 => 'Zenvo');
and some other code:
$pics = '';
$logos = "http://www.supercarworld.com/images/logos/";
$gif = ".gif";
for ($x = 0; $x < count($makes); $x++) {
$pics = array($logos.$makes[$x].$gif);
print_r($pics[$x]);
$car = new Car();
$car->setName('http://www.supercarworld.com/images/fullpics/595.jpg');
// em entity manager
$em = $this->getDoctrine()->getManager();
$em->persist($car);
$em->flush();
$car = $this->getDoctrine()
->getRepository('GrupaProjektBundle:Car')
->findOneBy(array('id' => $car->getId(), 'name' => $car->getName()));
return $this->render('GrupaProjektBundle:Sc:supercars.html.twig', array('car' => $car,
'pics' => $pics[$x],
));
}
and when I want to get [$x] the behaviour is weird it displays only zero element i.e 9FF but when I get [0] or [1] from $makes it works
Why?
I want to make it to iterate am I missing some incrementation?
$pics is not an array, or the way you are assigning it, it is an array with exactly one element & will get overwritten in each iteration of your for loop.
Did you mean to do that, or did you want
$pics = array();
Then in your for loop:
$pics[$x] = $logos.$makes[$x].$gif;
I'm guessing here as it's not immediately clear what you're trying to achieve. But I can certainly say you're overwriting $pics on each iteration of your for loop.

php mp3 string error

i have a mp3 class to read mp3s for my site. (i cannot install the module since its a shared hosting). i upload the mp3 and then the system read it using my class and insert into my mysql the file name and location, and the basic tag (artist, song name, album). the mysql insert is ok but i have problem with the strings i am inserting.
here's my code: http://pastebin.com/fXsm0c3T
<?php
class Id3 {
private $tags = array(
'TALB' => 'album', 'TCON' => 'genre', 'TENC' => 'encoder',
'TIT2' => 'title', 'TPE1' => 'artist', 'TPE2' => 'ensemble', 'TYER' => 'year', 'TCOM' => 'composer',
'TCOP' => 'copyright', 'TRCK' => 'track', 'WXXX' => 'url',
'COMM' => 'comment'
);
private $genre = array(
0 => 'Blues', 1 => 'Classic Rock', 2 => 'Country', 3 => 'Dance', 4 => 'Disco', 5 => 'Funk', 6 => 'Grunge', 7 => 'Hip-Hop', 8 => 'Jazz', 9 => 'Metal', 10 => 'New Age', 11 => 'Oldies', 12 => 'Other',
13 => 'Pop', 14 => 'R&B', 15 => 'Rap', 16 => 'Reggae', 17 => 'Rock', 18 => 'Techno', 19 => 'Industrial', 20 => 'Alternative', 21 => 'Ska', 22 => 'Death Metal', 23 => 'Pranks', 24 => 'Soundtrack', 25 => 'Euro-Techno', 26 => 'Ambient', 27 => 'Trip-Hop', 28 => 'Vocal',
29 => 'Jazz+Funk', 30 => 'Fusion', 31 => 'Trance', 32 => 'Classical', 33 => 'Instrumental', 34 => 'Acid', 35 => 'House',
36 => 'Game', 37 => 'Sound Clip', 38 => 'Gospel', 39 => 'Noise', 40 => 'Alternative Rock', 41 => 'Bass', 42 => 'Soul', 43 => 'Punk', 44 => 'Space', 45 => 'Meditative', 46 => 'Instrumental Pop', 47 => 'Instrumental Rock', 48 => 'Ethnic',
49 => 'Gothic', 50 => 'Darkwave', 51 => 'Techno-Industrial', 52 => 'Electronic', 53 => 'Pop-Folk', 54 => 'Eurodance', 55 => 'Dream', 56 => 'Southern Rock', 57 => 'Comedy', 58 => 'Cult', 59 => 'Gangsta', 60 => 'Top 40', 61 => 'Christian Rap', 62 => 'Pop/Funk', 63 => 'Jungle', 64 => 'Native US', 65 => 'Cabaret', 66 => 'New Wave', 67 => 'Psychadelic', 68 => 'Rave', 69 => 'Showtunes', 70 => 'Trailer', 71 => 'Lo-Fi', 72 => 'Tribal', 73 => 'Acid Punk', 74 => 'Acid Jazz', 75 => 'Polka', 76 => 'Retro', 77 => 'Musical', 78 => 'Rock & Roll', 79 => 'Hard Rock', 80 => 'Folk', 81 => 'Folk-Rock', 82 => 'National Folk', 83 => 'Swing', 84 => 'Fast Fusion', 85 => 'Bebob', 86 => 'Latin',
87 => 'Revival', 88 => 'Celtic', 89 => 'Bluegrass', 90 => 'Avantgarde', 91 => 'Gothic Rock', 92 => 'Progressive Rock', 93 => 'Psychedelic Rock', 94 => 'Symphonic Rock', 95 => 'Slow Rock', 96 => 'Big Band', 97 => 'Chorus', 98 => 'Easy Listening', 99 => 'Acoustic',
100 => 'Humour', 101 => 'Speech', 102 => 'Chanson', 103 => 'Opera', 104 => 'Chamber Music', 105 => 'Sonata', 106 => 'Symphony', 107 => 'Booty Bass', 108 => 'Primus', 109 => 'Porn Groove', 110 => 'Satire', 111 => 'Slow Jam', 112 => 'Club',
113 => 'Tango', 114 => 'Samba', 115 => 'Folklore', 116 => 'Ballad', 117 => 'Power Ballad', 118 => 'Rhytmic Soul', 119 => 'Freestyle', 120 => 'Duet', 121 => 'Punk Rock', 122 => 'Drum Solo', 123 => 'Acapella', 124 => 'Euro-House',
125 => 'Dance Hall', 126 => 'Goa', 127 => 'Drum & Bass', 128 => 'Club-House', 129 => 'Hardcore', 130 => 'Terror', 131 => 'Indie', 132 => 'BritPop', 133 => 'Negerpunk', 134 => 'Polsk Punk', 135 => 'Beat', 136 => 'Christian Gangsta Rap', 137 => 'Heavy Metal', 138 => 'Black Metal', 139 => 'Crossover', 140 => 'Contemporary Christian', 141 => 'Christian Rock', 142 => 'Merengue', 143 => 'Salsa', 144 => 'Trash Metal', 145 => 'Anime', 146 => 'Jpop', 147 => 'Synthpop'
);
public function __construct() {
$this->info = '';
}
private function getId3() {
$handle = fopen($this->file, 'r');
$head = fread($handle,10);
$head = unpack("a3signature/c1version_major/c1version_minor/c1flags/Nsize", $head);
$result = array();
for ($i = 0; $i<5; $i++){
$tag = trim(fread($handle, 6));
if (!isset($this->tags[$tag])) continue;
$size = fread($handle, 2);
$size = unpack('n', $size); $size = $size[1]+2;
$value = fread($handle, $size);
$this->info[$this->tags[$tag]] = $value;
} fclose($handle);
}
public function load($file) {
$this->file = $file; $this->getId3(); }
}
$id3 = new Id3();
$id3->load('mp3.mp3');
print_R($id3->info);
now, when i read the value i get this:
Array
(
[genre] => ��Rock
[title] => ��Walk
[artist] => ��Foo Fighters
[album] => ��Wasting Light
)
what is wrong with my code?
based on your code, the $value needs to be trim or converted to UTF (I prefer converting to UTF).
I added function that will check which UTF is the mp3 and parse it correctly:
$value = $this->filter($value, $tag); // convert to UTF or else that is why you have weird chars
Here's a readable code.
<?php
class Id3 {
private $tags = array(
'TALB' => 'album',
'TCON' => 'genre',
'TENC' => 'encoder',
'TIT2' => 'title',
'TPE1' => 'artist',
'TPE2' => 'ensemble',
'TYER' => 'year',
'TCOM' => 'composer',
'TCOP' => 'copyright',
'TRCK' => 'track',
'WXXX' => 'url',
'COMM' => 'comment'
);
private $genre = array(
0 => 'Blues',
1 => 'Classic Rock',
2 => 'Country',
3 => 'Dance',
4 => 'Disco',
5 => 'Funk',
6 => 'Grunge',
7 => 'Hip-Hop',
8 => 'Jazz',
9 => 'Metal',
10 => 'New Age',
11 => 'Oldies',
12 => 'Other',
13 => 'Pop',
14 => 'R&B',
15 => 'Rap',
16 => 'Reggae',
17 => 'Rock',
18 => 'Techno',
19 => 'Industrial',
20 => 'Alternative',
21 => 'Ska',
22 => 'Death Metal',
23 => 'Pranks',
24 => 'Soundtrack',
25 => 'Euro-Techno',
26 => 'Ambient',
27 => 'Trip-Hop',
28 => 'Vocal',
29 => 'Jazz+Funk',
30 => 'Fusion',
31 => 'Trance',
32 => 'Classical',
33 => 'Instrumental',
34 => 'Acid',
35 => 'House',
36 => 'Game',
37 => 'Sound Clip',
38 => 'Gospel',
39 => 'Noise',
40 => 'Alternative Rock',
41 => 'Bass',
42 => 'Soul',
43 => 'Punk',
44 => 'Space',
45 => 'Meditative',
46 => 'Instrumental Pop',
47 => 'Instrumental Rock',
48 => 'Ethnic',
49 => 'Gothic',
50 => 'Darkwave',
51 => 'Techno-Industrial',
52 => 'Electronic',
53 => 'Pop-Folk',
54 => 'Eurodance',
55 => 'Dream',
56 => 'Southern Rock',
57 => 'Comedy',
58 => 'Cult',
59 => 'Gangsta',
60 => 'Top 40',
61 => 'Christian Rap',
62 => 'Pop/Funk',
63 => 'Jungle',
64 => 'Native US',
65 => 'Cabaret',
66 => 'New Wave',
67 => 'Psychadelic',
68 => 'Rave',
69 => 'Showtunes',
70 => 'Trailer',
71 => 'Lo-Fi',
72 => 'Tribal',
73 => 'Acid Punk',
74 => 'Acid Jazz',
75 => 'Polka',
76 => 'Retro',
77 => 'Musical',
78 => 'Rock & Roll',
79 => 'Hard Rock',
80 => 'Folk',
81 => 'Folk-Rock',
82 => 'National Folk',
83 => 'Swing',
84 => 'Fast Fusion',
85 => 'Bebob',
86 => 'Latin',
87 => 'Revival',
88 => 'Celtic',
89 => 'Bluegrass',
90 => 'Avantgarde',
91 => 'Gothic Rock',
92 => 'Progressive Rock',
93 => 'Psychedelic Rock',
94 => 'Symphonic Rock',
95 => 'Slow Rock',
96 => 'Big Band',
97 => 'Chorus',
98 => 'Easy Listening',
99 => 'Acoustic',
100 => 'Humour',
101 => 'Speech',
102 => 'Chanson',
103 => 'Opera',
104 => 'Chamber Music',
105 => 'Sonata',
106 => 'Symphony',
107 => 'Booty Bass',
108 => 'Primus',
109 => 'Porn Groove',
110 => 'Satire',
111 => 'Slow Jam',
112 => 'Club',
113 => 'Tango',
114 => 'Samba',
115 => 'Folklore',
116 => 'Ballad',
117 => 'Power Ballad',
118 => 'Rhytmic Soul',
119 => 'Freestyle',
120 => 'Duet',
121 => 'Punk Rock',
122 => 'Drum Solo',
123 => 'Acapella',
124 => 'Euro-House',
125 => 'Dance Hall',
126 => 'Goa',
127 => 'Drum & Bass',
128 => 'Club-House',
129 => 'Hardcore',
130 => 'Terror',
131 => 'Indie',
132 => 'BritPop',
133 => 'Negerpunk',
134 => 'Polsk Punk',
135 => 'Beat',
136 => 'Christian Gangsta Rap',
137 => 'Heavy Metal',
138 => 'Black Metal',
139 => 'Crossover',
140 => 'Contemporary Christian',
141 => 'Christian Rock',
142 => 'Merengue',
143 => 'Salsa',
144 => 'Trash Metal',
145 => 'Anime',
146 => 'Jpop',
147 => 'Synthpop'
);
private $file;
private $info;
public function __construct() {
$this->info = array(
'genre' => 'unknow',
'title' => 'unknow',
'artist' => 'unknow',
'album' => 'unknow',
);
}
private function filter($tag, $type) {
if ($type == 'COMM') {
$tag = substr($tag, 0, 3) . substr($tag, 10);
}
if(ord($tag[2]) == 0) {
return iconv('UTF-8', 'ISO-8859-1', substr($tag, 3));
}
elseif(ord($tag[2]) == 1) {
return iconv('UTF-16LE', 'UTF-8', substr($tag, 5));
}
elseif(ord($tag[2]) == 2) {
return iconv('UTF-16BE', 'UTF-8', substr($tag, 5));
}
elseif(ord($tag[2]) == 3) {
return substr($tag, 3);
}
return false;
}
private function getId3() {
$handle = fopen($this->file, 'rb');
$head = fread($handle, 10);
$head = unpack("a3signature/c1version_major/c1version_minor/c1flags/Nsize", $head);
if (!$head['signature'] == 'ID3') {
fclose($handle);
return false;
}
$result = array();
for ($i = 0; $i < 22; $i++) { //22 most popular tags, you had 5 therefore only the first five.
$tag = rtrim(fread($handle, 6));
if (!isset($this->tags[$tag])) {
continue;
}
$size = fread($handle, 2);
$size = unpack('n', $size);
$size = $size[1]+2;
$value = fread($handle, $size);
$value = $this->filter($value, $tag); // convert to UTF or else that is why you have weird chars
$this->info[$this->tags[$tag]] = $value;
}
fclose($handle);
}
public function load($file) {
$this->file = $file;
$this->getId3();
}
public function getInfo() {
return $this->info;
}
}
$id3 = new Id3();
$id3->load('mp3.mp3');
print_R($id3->getInfo());
To get more information about tags, read this wiki article: http://en.wikipedia.org/wiki/ID3

Setting timezone to UTC (0) in PHP

Why does this work?
date_default_timezone_set('Australia/Currie');
But this doesn't seem to take any effect at all?
date_default_timezone_set('UTC');
This value doesn't change when setting the timezone to UTC:
echo date('Y-m-d H:i:s', time());
I'm using php 5.2.13, and the timezone of my server is:
$server_tz = date_default_timezone_get();
echo $server_tz; //outputs 'America/Guayaquil'
This is the original code:
echo time() . "<br>\n";
date_default_timezone_set('UTC');
echo time() . "<br>\n";
Output:
1317235130
1317235130
The problem is that you're displaying time(), which is a UNIX timestamp based on GMT/UTC. That’s why it doesn’t change. date() on the other hand, formats the time based on that timestamp.
A timestamp is the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
echo date('Y-m-d H:i:s T', time()) . "<br>\n";
date_default_timezone_set('UTC');
echo date('Y-m-d H:i:s T', time()) . "<br>\n";
UTC is definitely a valid timezone. It is simply an abbreviation for Coordinated Universal Time. In addition, remember that date_default_timezone_set accepts one of the following values:
$timezones=array(
"America/Adak",
"America/Argentina/Buenos_Aires",
"America/Argentina/La_Rioja",
"America/Argentina/San_Luis",
"America/Atikokan",
"America/Belem",
"America/Boise",
"America/Caracas",
"America/Chihuahua",
"America/Cuiaba",
"America/Denver",
"America/El_Salvador",
"America/Godthab",
"America/Guatemala",
"America/Hermosillo",
"America/Indiana/Tell_City",
"America/Inuvik",
"America/Kentucky/Louisville",
"America/Lima",
"America/Managua",
"America/Mazatlan",
"America/Mexico_City",
"America/Montreal",
"America/Nome",
"America/Ojinaga",
"America/Port-au-Prince",
"America/Rainy_River",
"America/Rio_Branco",
"America/Santo_Domingo",
"America/St_Barthelemy",
"America/St_Vincent",
"America/Tijuana",
"America/Whitehorse",
"America/Anchorage",
"America/Argentina/Catamarca",
"America/Argentina/Mendoza",
"America/Argentina/Tucuman",
"America/Atka",
"America/Belize",
"America/Buenos_Aires",
"America/Catamarca",
"America/Coral_Harbour",
"America/Curacao",
"America/Detroit",
"America/Ensenada",
"America/Goose_Bay",
"America/Guayaquil",
"America/Indiana/Indianapolis",
"America/Indiana/Vevay",
"America/Iqaluit",
"America/Kentucky/Monticello",
"America/Los_Angeles",
"America/Manaus",
"America/Mendoza",
"America/Miquelon",
"America/Montserrat",
"America/Noronha",
"America/Panama",
"America/Port_of_Spain",
"America/Rankin_Inlet",
"America/Rosario",
"America/Sao_Paulo",
"America/St_Johns",
"America/Swift_Current",
"America/Toronto",
"America/Winnipeg",
"America/Anguilla",
"America/Argentina/ComodRivadavia",
"America/Argentina/Rio_Gallegos",
"America/Argentina/Ushuaia",
"America/Bahia",
"America/Blanc-Sablon",
"America/Cambridge_Bay",
"America/Cayenne",
"America/Cordoba",
"America/Danmarkshavn",
"America/Dominica",
"America/Fort_Wayne",
"America/Grand_Turk",
"America/Guyana",
"America/Indiana/Knox",
"America/Indiana/Vincennes",
"America/Jamaica",
"America/Knox_IN",
"America/Louisville",
"America/Marigot",
"America/Menominee",
"America/Moncton",
"America/Nassau",
"America/North_Dakota/Beulah",
"America/Pangnirtung",
"America/Porto_Acre",
"America/Recife",
"America/Santa_Isabel",
"America/Scoresbysund",
"America/St_Kitts",
"America/Tegucigalpa",
"America/Tortola",
"America/Yakutat",
"America/Antigua",
"America/Argentina/Cordoba",
"America/Argentina/Salta",
"America/Aruba",
"America/Bahia_Banderas",
"America/Boa_Vista",
"America/Campo_Grande",
"America/Cayman",
"America/Costa_Rica",
"America/Dawson",
"America/Edmonton",
"America/Fortaleza",
"America/Grenada",
"America/Halifax",
"America/Indiana/Marengo",
"America/Indiana/Winamac",
"America/Jujuy",
"America/Kralendijk",
"America/Lower_Princes",
"America/Martinique",
"America/Merida",
"America/Monterrey",
"America/New_York",
"America/North_Dakota/Center",
"America/Paramaribo",
"America/Porto_Velho",
"America/Regina",
"America/Santarem",
"America/Shiprock",
"America/St_Lucia",
"America/Thule",
"America/Vancouver",
"America/Yellowknife",
"America/Araguaina",
"America/Argentina/Jujuy",
"America/Argentina/San_Juan",
"America/Asuncion",
"America/Barbados",
"America/Bogota",
"America/Cancun",
"America/Chicago",
"America/Creston",
"America/Dawson_Creek",
"America/Eirunepe",
"America/Glace_Bay",
"America/Guadeloupe",
"America/Havana",
"America/Indiana/Petersburg",
"America/Indianapolis",
"America/Juneau",
"America/La_Paz",
"America/Maceio",
"America/Matamoros",
"America/Metlakatla",
"America/Montevideo",
"America/Nipigon",
"America/North_Dakota/New_Salem",
"America/Phoenix",
"America/Puerto_Rico",
"America/Resolute",
"America/Santiago",
"America/Sitka",
"America/St_Thomas",
"America/Thunder_Bay",
"America/Virgin",
"Indian/Antananarivo",
"Indian/Kerguelen",
"Indian/Reunion",
"Australia/ACT",
"Australia/Currie",
"Australia/Lindeman",
"Australia/Perth",
"Australia/Victoria",
"Europe/Amsterdam",
"Europe/Berlin",
"Europe/Chisinau",
"Europe/Helsinki",
"Europe/Kiev",
"Europe/Madrid",
"Europe/Moscow",
"Europe/Prague",
"Europe/Sarajevo",
"Europe/Tallinn",
"Europe/Vatican",
"Europe/Zagreb",
"Pacific/Apia",
"Pacific/Efate",
"Pacific/Galapagos",
"Pacific/Johnston",
"Pacific/Marquesas",
"Pacific/Noumea",
"Pacific/Ponape",
"Pacific/Tahiti",
"Pacific/Wallis",
"Indian/Chagos",
"Indian/Mahe",
"Australia/Adelaide",
"Australia/Darwin",
"Australia/Lord_Howe",
"Australia/Queensland",
"Australia/West",
"Europe/Andorra",
"Europe/Bratislava",
"Europe/Copenhagen",
"Europe/Isle_of_Man",
"Europe/Lisbon",
"Europe/Malta",
"Europe/Nicosia",
"Europe/Riga",
"Europe/Simferopol",
"Europe/Tirane",
"Europe/Vienna",
"Europe/Zaporozhye",
"Pacific/Auckland",
"Pacific/Enderbury",
"Pacific/Gambier",
"Pacific/Kiritimati",
"Pacific/Midway",
"Pacific/Pago_Pago",
"Pacific/Port_Moresby",
"Pacific/Tarawa",
"Pacific/Yap",
"Africa/Abidjan",
"Africa/Asmera",
"Africa/Blantyre",
"Africa/Ceuta",
"Africa/Douala",
"Africa/Johannesburg",
"Africa/Kinshasa",
"Africa/Lubumbashi",
"Africa/Mbabane",
"Africa/Niamey",
"Africa/Timbuktu",
"Africa/Accra",
"Africa/Bamako",
"Africa/Brazzaville",
"Africa/Conakry",
"Africa/El_Aaiun",
"Africa/Juba",
"Africa/Lagos",
"Africa/Lusaka",
"Africa/Mogadishu",
"Africa/Nouakchott",
"Africa/Tripoli",
"Africa/Addis_Ababa",
"Africa/Bangui",
"Africa/Bujumbura",
"Africa/Dakar",
"Africa/Freetown",
"Africa/Kampala",
"Africa/Libreville",
"Africa/Malabo",
"Africa/Monrovia",
"Africa/Ouagadougou",
"Africa/Tunis",
"Africa/Algiers",
"Africa/Banjul",
"Africa/Cairo",
"Africa/Dar_es_Salaam",
"Africa/Gaborone",
"Africa/Khartoum",
"Africa/Lome",
"Africa/Maputo",
"Africa/Nairobi",
"Africa/Porto-Novo",
"Africa/Windhoek",
"Africa/Asmara",
"Africa/Bissau",
"Africa/Casablanca",
"Africa/Djibouti",
"Africa/Harare",
"Africa/Kigali",
"Africa/Luanda",
"Africa/Maseru",
"Africa/Ndjamena",
"Africa/Sao_Tome",
"Atlantic/Azores",
"Atlantic/Faroe",
"Atlantic/St_Helena",
"Atlantic/Bermuda",
"Atlantic/Jan_Mayen",
"Atlantic/Stanley",
"Atlantic/Canary",
"Atlantic/Madeira",
"Atlantic/Cape_Verde",
"Atlantic/Reykjavik",
"Atlantic/Faeroe",
"Atlantic/South_Georgia",
"Asia/Aden",
"Asia/Aqtobe",
"Asia/Baku",
"Asia/Calcutta",
"Asia/Dacca",
"Asia/Dushanbe",
"Asia/Hong_Kong",
"Asia/Jayapura",
"Asia/Kashgar",
"Asia/Kuala_Lumpur",
"Asia/Magadan",
"Asia/Novokuznetsk",
"Asia/Pontianak",
"Asia/Riyadh",
"Asia/Shanghai",
"Asia/Tehran",
"Asia/Ujung_Pandang",
"Asia/Vladivostok",
"Asia/Almaty",
"Asia/Ashgabat",
"Asia/Bangkok",
"Asia/Choibalsan",
"Asia/Damascus",
"Asia/Gaza",
"Asia/Hovd",
"Asia/Jerusalem",
"Asia/Kathmandu",
"Asia/Kuching",
"Asia/Makassar",
"Asia/Novosibirsk",
"Asia/Pyongyang",
"Asia/Saigon",
"Asia/Singapore",
"Asia/Tel_Aviv",
"Asia/Ulaanbaatar",
"Asia/Yakutsk",
"Asia/Amman",
"Asia/Ashkhabad",
"Asia/Beirut",
"Asia/Chongqing",
"Asia/Dhaka",
"Asia/Harbin",
"Asia/Irkutsk",
"Asia/Kabul",
"Asia/Katmandu",
"Asia/Kuwait",
"Asia/Manila",
"Asia/Omsk",
"Asia/Qatar",
"Asia/Sakhalin",
"Asia/Taipei",
"Asia/Thimbu",
"Asia/Ulan_Bator",
"Asia/Yekaterinburg",
"Asia/Anadyr",
"Asia/Baghdad",
"Asia/Bishkek",
"Asia/Chungking",
"Asia/Dili",
"Asia/Hebron",
"Asia/Istanbul",
"Asia/Kamchatka",
"Asia/Kolkata",
"Asia/Macao",
"Asia/Muscat",
"Asia/Oral",
"Asia/Qyzylorda",
"Asia/Samarkand",
"Asia/Tashkent",
"Asia/Thimphu",
"Asia/Urumqi",
"Asia/Yerevan",
"Asia/Aqtau",
"Asia/Bahrain",
"Asia/Brunei",
"Asia/Colombo",
"Asia/Dubai",
"Asia/Ho_Chi_Minh",
"Asia/Jakarta",
"Asia/Karachi",
"Asia/Krasnoyarsk",
"Asia/Macau",
"Asia/Nicosia",
"Asia/Phnom_Penh",
"Asia/Rangoon",
"Asia/Seoul",
"Asia/Tbilisi",
"Asia/Tokyo",
"Asia/Vientiane",
"Australia/Canberra",
"Australia/LHI",
"Australia/NSW",
"Australia/Tasmania",
"Australia/Broken_Hill",
"Australia/Hobart",
"Australia/North",
"Australia/Sydney",
"Pacific/Chuuk",
"Pacific/Fiji",
"Pacific/Guam",
"Pacific/Kwajalein",
"Pacific/Niue",
"Pacific/Pitcairn",
"Pacific/Saipan",
"Pacific/Truk",
"Pacific/Chatham",
"Pacific/Fakaofo",
"Pacific/Guadalcanal",
"Pacific/Kosrae",
"Pacific/Nauru",
"Pacific/Palau",
"Pacific/Rarotonga",
"Pacific/Tongatapu",
"Pacific/Easter",
"Pacific/Funafuti",
"Pacific/Honolulu",
"Pacific/Majuro",
"Pacific/Norfolk",
"Pacific/Pohnpei",
"Pacific/Samoa",
"Pacific/Wake",
"Antarctica/Casey",
"Antarctica/McMurdo",
"Antarctica/Vostok",
"Antarctica/Davis",
"Antarctica/Palmer",
"Antarctica/DumontDUrville",
"Antarctica/Rothera",
"Antarctica/Macquarie",
"Antarctica/South_Pole",
"Antarctica/Mawson",
"Antarctica/Syowa",
"Arctic/Longyearbyen",
"Europe/Athens",
"Europe/Brussels",
"Europe/Dublin",
"Europe/Istanbul",
"Europe/Ljubljana",
"Europe/Mariehamn",
"Europe/Oslo",
"Europe/Rome",
"Europe/Skopje",
"Europe/Tiraspol",
"Europe/Vilnius",
"Europe/Zurich",
"Europe/Belfast",
"Europe/Bucharest",
"Europe/Gibraltar",
"Europe/Jersey",
"Europe/London",
"Europe/Minsk",
"Europe/Paris",
"Europe/Samara",
"Europe/Sofia",
"Europe/Uzhgorod",
"Europe/Volgograd",
"Europe/Belgrade",
"Europe/Budapest",
"Europe/Guernsey",
"Europe/Kaliningrad",
"Europe/Luxembourg",
"Europe/Monaco",
"Europe/Podgorica",
"Europe/San_Marino",
"Europe/Stockholm",
"Europe/Vaduz",
"Europe/Warsaw",
"Indian/Cocos",
"Indian/Mauritius",
"Indian/Christmas",
"Indian/Maldives",
"Indian/Comoro",
"Indian/Mayotte",
"Australia/Brisbane",
"Australia/Eucla",
"Australia/Melbourne",
"Australia/South",
"Australia/Yancowinna",
);
Timezones in PHP at http://www.php.net/manual/en/timezones.php
List of entire available timezones.
$time_zones = array (
0 => 'Africa/Abidjan',
1 => 'Africa/Accra',
2 => 'Africa/Addis_Ababa',
3 => 'Africa/Algiers',
4 => 'Africa/Asmara',
5 => 'Africa/Asmera',
6 => 'Africa/Bamako',
7 => 'Africa/Bangui',
8 => 'Africa/Banjul',
9 => 'Africa/Bissau',
10 => 'Africa/Blantyre',
11 => 'Africa/Brazzaville',
12 => 'Africa/Bujumbura',
13 => 'Africa/Cairo',
14 => 'Africa/Casablanca',
15 => 'Africa/Ceuta',
16 => 'Africa/Conakry',
17 => 'Africa/Dakar',
18 => 'Africa/Dar_es_Salaam',
19 => 'Africa/Djibouti',
20 => 'Africa/Douala',
21 => 'Africa/El_Aaiun',
22 => 'Africa/Freetown',
23 => 'Africa/Gaborone',
24 => 'Africa/Harare',
25 => 'Africa/Johannesburg',
26 => 'Africa/Juba',
27 => 'Africa/Kampala',
28 => 'Africa/Khartoum',
29 => 'Africa/Kigali',
30 => 'Africa/Kinshasa',
31 => 'Africa/Lagos',
32 => 'Africa/Libreville',
33 => 'Africa/Lome',
34 => 'Africa/Luanda',
35 => 'Africa/Lubumbashi',
36 => 'Africa/Lusaka',
37 => 'Africa/Malabo',
38 => 'Africa/Maputo',
39 => 'Africa/Maseru',
40 => 'Africa/Mbabane',
41 => 'Africa/Mogadishu',
42 => 'Africa/Monrovia',
43 => 'Africa/Nairobi',
44 => 'Africa/Ndjamena',
45 => 'Africa/Niamey',
46 => 'Africa/Nouakchott',
47 => 'Africa/Ouagadougou',
48 => 'Africa/Porto-Novo',
49 => 'Africa/Sao_Tome',
50 => 'Africa/Timbuktu',
51 => 'Africa/Tripoli',
52 => 'Africa/Tunis',
53 => 'Africa/Windhoek',
54 => 'America/Adak',
55 => 'America/Anchorage',
56 => 'America/Anguilla',
57 => 'America/Antigua',
58 => 'America/Araguaina',
59 => 'America/Argentina/Buenos_Aires',
60 => 'America/Argentina/Catamarca',
61 => 'America/Argentina/ComodRivadavia',
62 => 'America/Argentina/Cordoba',
63 => 'America/Argentina/Jujuy',
64 => 'America/Argentina/La_Rioja',
65 => 'America/Argentina/Mendoza',
66 => 'America/Argentina/Rio_Gallegos',
67 => 'America/Argentina/Salta',
68 => 'America/Argentina/San_Juan',
69 => 'America/Argentina/San_Luis',
70 => 'America/Argentina/Tucuman',
71 => 'America/Argentina/Ushuaia',
72 => 'America/Aruba',
73 => 'America/Asuncion',
74 => 'America/Atikokan',
75 => 'America/Atka',
76 => 'America/Bahia',
77 => 'America/Bahia_Banderas',
78 => 'America/Barbados',
79 => 'America/Belem',
80 => 'America/Belize',
81 => 'America/Blanc-Sablon',
82 => 'America/Boa_Vista',
83 => 'America/Bogota',
84 => 'America/Boise',
85 => 'America/Buenos_Aires',
86 => 'America/Cambridge_Bay',
87 => 'America/Campo_Grande',
88 => 'America/Cancun',
89 => 'America/Caracas',
90 => 'America/Catamarca',
91 => 'America/Cayenne',
92 => 'America/Cayman',
93 => 'America/Chicago',
94 => 'America/Chihuahua',
95 => 'America/Coral_Harbour',
96 => 'America/Cordoba',
97 => 'America/Costa_Rica',
98 => 'America/Creston',
99 => 'America/Cuiaba',
100 => 'America/Curacao',
101 => 'America/Danmarkshavn',
102 => 'America/Dawson',
103 => 'America/Dawson_Creek',
104 => 'America/Denver',
105 => 'America/Detroit',
106 => 'America/Dominica',
107 => 'America/Edmonton',
108 => 'America/Eirunepe',
109 => 'America/El_Salvador',
110 => 'America/Ensenada',
111 => 'America/Fort_Nelson',
112 => 'America/Fort_Wayne',
113 => 'America/Fortaleza',
114 => 'America/Glace_Bay',
115 => 'America/Godthab',
116 => 'America/Goose_Bay',
117 => 'America/Grand_Turk',
118 => 'America/Grenada',
119 => 'America/Guadeloupe',
120 => 'America/Guatemala',
121 => 'America/Guayaquil',
122 => 'America/Guyana',
123 => 'America/Halifax',
124 => 'America/Havana',
125 => 'America/Hermosillo',
126 => 'America/Indiana/Indianapolis',
127 => 'America/Indiana/Knox',
128 => 'America/Indiana/Marengo',
129 => 'America/Indiana/Petersburg',
130 => 'America/Indiana/Tell_City',
131 => 'America/Indiana/Vevay',
132 => 'America/Indiana/Vincennes',
133 => 'America/Indiana/Winamac',
134 => 'America/Indianapolis',
135 => 'America/Inuvik',
136 => 'America/Iqaluit',
137 => 'America/Jamaica',
138 => 'America/Jujuy',
139 => 'America/Juneau',
140 => 'America/Kentucky/Louisville',
141 => 'America/Kentucky/Monticello',
142 => 'America/Knox_IN',
143 => 'America/Kralendijk',
144 => 'America/La_Paz',
145 => 'America/Lima',
146 => 'America/Los_Angeles',
147 => 'America/Louisville',
148 => 'America/Lower_Princes',
149 => 'America/Maceio',
150 => 'America/Managua',
151 => 'America/Manaus',
152 => 'America/Marigot',
153 => 'America/Martinique',
154 => 'America/Matamoros',
155 => 'America/Mazatlan',
156 => 'America/Mendoza',
157 => 'America/Menominee',
158 => 'America/Merida',
159 => 'America/Metlakatla',
160 => 'America/Mexico_City',
161 => 'America/Miquelon',
162 => 'America/Moncton',
163 => 'America/Monterrey',
164 => 'America/Montevideo',
165 => 'America/Montreal',
166 => 'America/Montserrat',
167 => 'America/Nassau',
168 => 'America/New_York',
169 => 'America/Nipigon',
170 => 'America/Nome',
171 => 'America/Noronha',
172 => 'America/North_Dakota/Beulah',
173 => 'America/North_Dakota/Center',
174 => 'America/North_Dakota/New_Salem',
175 => 'America/Ojinaga',
176 => 'America/Panama',
177 => 'America/Pangnirtung',
178 => 'America/Paramaribo',
179 => 'America/Phoenix',
180 => 'America/Port-au-Prince',
181 => 'America/Port_of_Spain',
182 => 'America/Porto_Acre',
183 => 'America/Porto_Velho',
184 => 'America/Puerto_Rico',
185 => 'America/Rainy_River',
186 => 'America/Rankin_Inlet',
187 => 'America/Recife',
188 => 'America/Regina',
189 => 'America/Resolute',
190 => 'America/Rio_Branco',
191 => 'America/Rosario',
192 => 'America/Santa_Isabel',
193 => 'America/Santarem',
194 => 'America/Santiago',
195 => 'America/Santo_Domingo',
196 => 'America/Sao_Paulo',
197 => 'America/Scoresbysund',
198 => 'America/Shiprock',
199 => 'America/Sitka',
200 => 'America/St_Barthelemy',
201 => 'America/St_Johns',
202 => 'America/St_Kitts',
203 => 'America/St_Lucia',
204 => 'America/St_Thomas',
205 => 'America/St_Vincent',
206 => 'America/Swift_Current',
207 => 'America/Tegucigalpa',
208 => 'America/Thule',
209 => 'America/Thunder_Bay',
210 => 'America/Tijuana',
211 => 'America/Toronto',
212 => 'America/Tortola',
213 => 'America/Vancouver',
214 => 'America/Virgin',
215 => 'America/Whitehorse',
216 => 'America/Winnipeg',
217 => 'America/Yakutat',
218 => 'America/Yellowknife',
219 => 'Antarctica/Casey',
220 => 'Antarctica/Davis',
221 => 'Antarctica/DumontDUrville',
222 => 'Antarctica/Macquarie',
223 => 'Antarctica/Mawson',
224 => 'Antarctica/McMurdo',
225 => 'Antarctica/Palmer',
226 => 'Antarctica/Rothera',
227 => 'Antarctica/South_Pole',
228 => 'Antarctica/Syowa',
229 => 'Antarctica/Troll',
230 => 'Antarctica/Vostok',
231 => 'Arctic/Longyearbyen',
232 => 'Asia/Aden',
233 => 'Asia/Almaty',
234 => 'Asia/Amman',
235 => 'Asia/Anadyr',
236 => 'Asia/Aqtau',
237 => 'Asia/Aqtobe',
238 => 'Asia/Ashgabat',
239 => 'Asia/Ashkhabad',
240 => 'Asia/Baghdad',
241 => 'Asia/Bahrain',
242 => 'Asia/Baku',
243 => 'Asia/Bangkok',
244 => 'Asia/Beirut',
245 => 'Asia/Bishkek',
246 => 'Asia/Brunei',
247 => 'Asia/Calcutta',
248 => 'Asia/Chita',
249 => 'Asia/Choibalsan',
250 => 'Asia/Chongqing',
251 => 'Asia/Chungking',
252 => 'Asia/Colombo',
253 => 'Asia/Dacca',
254 => 'Asia/Damascus',
255 => 'Asia/Dhaka',
256 => 'Asia/Dili',
257 => 'Asia/Dubai',
258 => 'Asia/Dushanbe',
259 => 'Asia/Gaza',
260 => 'Asia/Harbin',
261 => 'Asia/Hebron',
262 => 'Asia/Ho_Chi_Minh',
263 => 'Asia/Hong_Kong',
264 => 'Asia/Hovd',
265 => 'Asia/Irkutsk',
266 => 'Asia/Istanbul',
267 => 'Asia/Jakarta',
268 => 'Asia/Jayapura',
269 => 'Asia/Jerusalem',
270 => 'Asia/Kabul',
271 => 'Asia/Kamchatka',
272 => 'Asia/Karachi',
273 => 'Asia/Kashgar',
274 => 'Asia/Kathmandu',
275 => 'Asia/Katmandu',
276 => 'Asia/Khandyga',
277 => 'Asia/Kolkata',
278 => 'Asia/Krasnoyarsk',
279 => 'Asia/Kuala_Lumpur',
280 => 'Asia/Kuching',
281 => 'Asia/Kuwait',
282 => 'Asia/Macao',
283 => 'Asia/Macau',
284 => 'Asia/Magadan',
285 => 'Asia/Makassar',
286 => 'Asia/Manila',
287 => 'Asia/Muscat',
288 => 'Asia/Nicosia',
289 => 'Asia/Novokuznetsk',
290 => 'Asia/Novosibirsk',
291 => 'Asia/Omsk',
292 => 'Asia/Oral',
293 => 'Asia/Phnom_Penh',
294 => 'Asia/Pontianak',
295 => 'Asia/Pyongyang',
296 => 'Asia/Qatar',
297 => 'Asia/Qyzylorda',
298 => 'Asia/Rangoon',
299 => 'Asia/Riyadh',
300 => 'Asia/Saigon',
301 => 'Asia/Sakhalin',
302 => 'Asia/Samarkand',
303 => 'Asia/Seoul',
304 => 'Asia/Shanghai',
305 => 'Asia/Singapore',
306 => 'Asia/Srednekolymsk',
307 => 'Asia/Taipei',
308 => 'Asia/Tashkent',
309 => 'Asia/Tbilisi',
310 => 'Asia/Tehran',
311 => 'Asia/Tel_Aviv',
312 => 'Asia/Thimbu',
313 => 'Asia/Thimphu',
314 => 'Asia/Tokyo',
315 => 'Asia/Ujung_Pandang',
316 => 'Asia/Ulaanbaatar',
317 => 'Asia/Ulan_Bator',
318 => 'Asia/Urumqi',
319 => 'Asia/Ust-Nera',
320 => 'Asia/Vientiane',
321 => 'Asia/Vladivostok',
322 => 'Asia/Yakutsk',
323 => 'Asia/Yekaterinburg',
324 => 'Asia/Yerevan',
325 => 'Atlantic/Azores',
326 => 'Atlantic/Bermuda',
327 => 'Atlantic/Canary',
328 => 'Atlantic/Cape_Verde',
329 => 'Atlantic/Faeroe',
330 => 'Atlantic/Faroe',
331 => 'Atlantic/Jan_Mayen',
332 => 'Atlantic/Madeira',
333 => 'Atlantic/Reykjavik',
334 => 'Atlantic/South_Georgia',
335 => 'Atlantic/St_Helena',
336 => 'Atlantic/Stanley',
337 => 'Australia/ACT',
338 => 'Australia/Adelaide',
339 => 'Australia/Brisbane',
340 => 'Australia/Broken_Hill',
341 => 'Australia/Canberra',
342 => 'Australia/Currie',
343 => 'Australia/Darwin',
344 => 'Australia/Eucla',
345 => 'Australia/Hobart',
346 => 'Australia/LHI',
347 => 'Australia/Lindeman',
348 => 'Australia/Lord_Howe',
349 => 'Australia/Melbourne',
350 => 'Australia/North',
351 => 'Australia/NSW',
352 => 'Australia/Perth',
353 => 'Australia/Queensland',
354 => 'Australia/South',
355 => 'Australia/Sydney',
356 => 'Australia/Tasmania',
357 => 'Australia/Victoria',
358 => 'Australia/West',
359 => 'Australia/Yancowinna',
360 => 'Europe/Amsterdam',
361 => 'Europe/Andorra',
362 => 'Europe/Athens',
363 => 'Europe/Belfast',
364 => 'Europe/Belgrade',
365 => 'Europe/Berlin',
366 => 'Europe/Bratislava',
367 => 'Europe/Brussels',
368 => 'Europe/Bucharest',
369 => 'Europe/Budapest',
370 => 'Europe/Busingen',
371 => 'Europe/Chisinau',
372 => 'Europe/Copenhagen',
373 => 'Europe/Dublin',
374 => 'Europe/Gibraltar',
375 => 'Europe/Guernsey',
376 => 'Europe/Helsinki',
377 => 'Europe/Isle_of_Man',
378 => 'Europe/Istanbul',
379 => 'Europe/Jersey',
380 => 'Europe/Kaliningrad',
381 => 'Europe/Kiev',
382 => 'Europe/Lisbon',
383 => 'Europe/Ljubljana',
384 => 'Europe/London',
385 => 'Europe/Luxembourg',
386 => 'Europe/Madrid',
387 => 'Europe/Malta',
388 => 'Europe/Mariehamn',
389 => 'Europe/Minsk',
390 => 'Europe/Monaco',
391 => 'Europe/Moscow',
392 => 'Europe/Nicosia',
393 => 'Europe/Oslo',
394 => 'Europe/Paris',
395 => 'Europe/Podgorica',
396 => 'Europe/Prague',
397 => 'Europe/Riga',
398 => 'Europe/Rome',
399 => 'Europe/Samara',
400 => 'Europe/San_Marino',
401 => 'Europe/Sarajevo',
402 => 'Europe/Simferopol',
403 => 'Europe/Skopje',
404 => 'Europe/Sofia',
405 => 'Europe/Stockholm',
406 => 'Europe/Tallinn',
407 => 'Europe/Tirane',
408 => 'Europe/Tiraspol',
409 => 'Europe/Uzhgorod',
410 => 'Europe/Vaduz',
411 => 'Europe/Vatican',
412 => 'Europe/Vienna',
413 => 'Europe/Vilnius',
414 => 'Europe/Volgograd',
415 => 'Europe/Warsaw',
416 => 'Europe/Zagreb',
417 => 'Europe/Zaporozhye',
418 => 'Europe/Zurich',
419 => 'Indian/Antananarivo',
420 => 'Indian/Chagos',
421 => 'Indian/Christmas',
422 => 'Indian/Cocos',
423 => 'Indian/Comoro',
424 => 'Indian/Kerguelen',
425 => 'Indian/Mahe',
426 => 'Indian/Maldives',
427 => 'Indian/Mauritius',
428 => 'Indian/Mayotte',
429 => 'Indian/Reunion',
430 => 'Pacific/Apia',
431 => 'Pacific/Auckland',
432 => 'Pacific/Bougainville',
433 => 'Pacific/Chatham',
434 => 'Pacific/Chuuk',
435 => 'Pacific/Easter',
436 => 'Pacific/Efate',
437 => 'Pacific/Enderbury',
438 => 'Pacific/Fakaofo',
439 => 'Pacific/Fiji',
440 => 'Pacific/Funafuti',
441 => 'Pacific/Galapagos',
442 => 'Pacific/Gambier',
443 => 'Pacific/Guadalcanal',
444 => 'Pacific/Guam',
445 => 'Pacific/Honolulu',
446 => 'Pacific/Johnston',
447 => 'Pacific/Kiritimati',
448 => 'Pacific/Kosrae',
449 => 'Pacific/Kwajalein',
450 => 'Pacific/Majuro',
451 => 'Pacific/Marquesas',
452 => 'Pacific/Midway',
453 => 'Pacific/Nauru',
454 => 'Pacific/Niue',
455 => 'Pacific/Norfolk',
456 => 'Pacific/Noumea',
457 => 'Pacific/Pago_Pago',
458 => 'Pacific/Palau',
459 => 'Pacific/Pitcairn',
460 => 'Pacific/Pohnpei',
461 => 'Pacific/Ponape',
462 => 'Pacific/Port_Moresby',
463 => 'Pacific/Rarotonga',
464 => 'Pacific/Saipan',
465 => 'Pacific/Samoa',
466 => 'Pacific/Tahiti',
467 => 'Pacific/Tarawa',
468 => 'Pacific/Tongatapu',
469 => 'Pacific/Truk',
470 => 'Pacific/Wake',
471 => 'Pacific/Wallis',
472 => 'Pacific/Yap',
473 => 'Brazil/Acre',
474 => 'Brazil/DeNoronha',
475 => 'Brazil/East',
476 => 'Brazil/West',
477 => 'Canada/Atlantic',
478 => 'Canada/Central',
479 => 'Canada/East-Saskatchewan',
480 => 'Canada/Eastern',
481 => 'Canada/Mountain',
482 => 'Canada/Newfoundland',
483 => 'Canada/Pacific',
484 => 'Canada/Saskatchewan',
485 => 'Canada/Yukon',
486 => 'CET',
487 => 'Chile/Continental',
488 => 'Chile/EasterIsland',
489 => 'CST6CDT',
490 => 'Cuba',
491 => 'EET',
492 => 'Egypt',
493 => 'Eire',
494 => 'EST',
495 => 'EST5EDT',
496 => 'Etc/GMT',
497 => 'Etc/GMT+0',
498 => 'Etc/GMT+1',
499 => 'Etc/GMT+10',
500 => 'Etc/GMT+11',
501 => 'Etc/GMT+12',
502 => 'Etc/GMT+2',
503 => 'Etc/GMT+3',
504 => 'Etc/GMT+4',
505 => 'Etc/GMT+5',
506 => 'Etc/GMT+6',
507 => 'Etc/GMT+7',
508 => 'Etc/GMT+8',
509 => 'Etc/GMT+9',
510 => 'Etc/GMT-0',
511 => 'Etc/GMT-1',
512 => 'Etc/GMT-10',
513 => 'Etc/GMT-11',
514 => 'Etc/GMT-12',
515 => 'Etc/GMT-13',
516 => 'Etc/GMT-14',
517 => 'Etc/GMT-2',
518 => 'Etc/GMT-3',
519 => 'Etc/GMT-4',
520 => 'Etc/GMT-5',
521 => 'Etc/GMT-6',
522 => 'Etc/GMT-7',
523 => 'Etc/GMT-8',
524 => 'Etc/GMT-9',
525 => 'Etc/GMT0',
526 => 'Etc/Greenwich',
527 => 'Etc/UCT',
528 => 'Etc/Universal',
529 => 'Etc/UTC',
530 => 'Etc/Zulu',
531 => 'Factory',
532 => 'GB',
533 => 'GB-Eire',
534 => 'GMT',
535 => 'GMT+0',
536 => 'GMT-0',
537 => 'GMT0',
538 => 'Greenwich',
539 => 'Hongkong',
540 => 'HST',
541 => 'Iceland',
542 => 'Iran',
543 => 'Israel',
544 => 'Jamaica',
545 => 'Japan',
546 => 'Kwajalein',
547 => 'Libya',
548 => 'MET',
549 => 'Mexico/BajaNorte',
550 => 'Mexico/BajaSur',
551 => 'Mexico/General',
552 => 'MST',
553 => 'MST7MDT',
554 => 'Navajo',
555 => 'NZ',
556 => 'NZ-CHAT',
557 => 'Poland',
558 => 'Portugal',
559 => 'PRC',
560 => 'PST8PDT',
561 => 'ROC',
562 => 'ROK',
563 => 'Singapore',
564 => 'Turkey',
565 => 'UCT',
566 => 'Universal',
567 => 'US/Alaska',
568 => 'US/Aleutian',
569 => 'US/Arizona',
570 => 'US/Central',
571 => 'US/East-Indiana',
572 => 'US/Eastern',
573 => 'US/Hawaii',
574 => 'US/Indiana-Starke',
575 => 'US/Michigan',
576 => 'US/Mountain',
577 => 'US/Pacific',
578 => 'US/Pacific-New',
579 => 'US/Samoa',
580 => 'UTC',
581 => 'W-SU',
582 => 'WET',
583 => 'Zulu',
)
Is 'UTC' a valid timezone identifier on your system?
<?php
if (date_default_timezone_set('UTC')){
echo "UTC is a valid time zone";
}else{
echo "The system doesn't know WTFUTC. Maybe try updating tzinfo with your package manager?";
}
In PHP DateTime (PHP >= 5.3)
$dt = new DateTime();
$dt->setTimezone(new DateTimeZone('UTC'));
echo $dt->getTimestamp();
You can always check this maintained list to timezones
https://www.php.net/manual/en/function.date.php

Categories