Skip to content

Instantly share code, notes, and snippets.

@prionkor
Last active January 3, 2016 20:59
Show Gist options
  • Save prionkor/8518651 to your computer and use it in GitHub Desktop.
Save prionkor/8518651 to your computer and use it in GitHub Desktop.
function kallzu_parse_csv2($csv_url){
ini_set('auto_detect_line_endings', true);
$result = array();
$file = fopen($csv_url, 'r');
while (($line = fgetcsv($file)) !== FALSE) {
//$line is an array of the csv elements
$result[] = $line;
}
fclose($file);
return $result;
}
function kallzu_parse_csv($csv_url){
ini_set('auto_detect_line_endings', true);
$response = wp_remote_get($csv_url);
$content = wp_remote_retrieve_body($response);
return str_getcsv($content);
}
Array ( [0] => ISO [1] => Country [2] => Country Code [3] => Type of number [4] => Voice Enabled [5] => SMS Enabled [6] => MMS Enabled [7] => Price /num/month [8] => Inbound Voice price/min [9] => Inbound SMS price/msg [10] => Inbound MMS price/msg [11] => Beta Status [12] => Address Required AT [13] => Austria [14] => 43 [15] => National [16] => Yes [17] => No [18] => No [19] => $1.00 [20] => $0.01 [21] => N/A [22] => N/A [23] => No [24] => No AU [25] => Australia [26] => 61 [27] => Local [28] => Yes [29] => No [30] => No [31] => $3.00 [32] => $0.01 [33] => N/A [34] => N/A [35] => No [36] => Yes BE [37] => Belgium [38] => 32 [39] => Local [40] => Yes [41] => No [42] => No [43] => $1.00 [44] => $0.01 [45] => N/A [46] => N/A [47] => Yes [48] => Yes BE [49] => Belgium [50] => 32 [51] => Mobile [52] => No [53] => Yes [54] => No [55] => $1.00 [56] => N/A [57] => $0.0075 [58] => N/A [59] => Yes [60] => No BE [61] => Belgium [62] => 32 [63] => National [64] => Yes [65] => No [66] => No [67] => $1.00 [68] => $0.01 [69] => N/A [70] => N/A [71] => No [72] => No BG [73] => Bulgaria [74] => 359 [75] => Local [76] => Yes [77] => No [78] => No [79] => $1.00 [80] => $0.01 [81] => N/A [82] => N/A [83] => No [84] => Yes BH [85] => Bahrain [86] => 973 [87] => Local [88] => Yes [89] => No [90] => No [91] => $8.00 [92] => $0.01 [93] => N/A [94] => N/A [95] => Yes [96] => No BR [97] => Brazil [98] => 55 [99] => Local [100] => Yes [101] => No [102] => No [103] => $3.00 [104] => $0.01 [105] => N/A [106] => N/A [107] => Yes [108] => No CA [109] => Canada [110] => 1 [111] => Local [112] => Yes [113] => Yes [114] => Yes [115] => $1.00 [116] => $0.01 [117] => $0.0075 [118] => $0.0100 [119] => No [120] => No CA [121] => Canada [122] => 1 [123] => Toll Free [124] => Yes [125] => No [126] => No [127] => $2.00 [128] => $0.03 [129] => N/A [130] => N/A [131] => No [132] => No CH [133] => Switzerland [134] => 41 [135] => Local [136] => Yes [137] => No [138] => No [139] => $1.00 [140] => $0.01 [141] => N/A [142] => N/A [143] => No [144] => Yes CY [145] => Cyprus [146] => 357 [147] => National [148] => Yes [149] => No [150] => No [151] => $4.00 [152] => $0.01 [153] => N/A [154] => N/A [155] => Yes [156] => No CZ [157] => Czech Republic [158] => 420 [159] => Local [160] => Yes [161] => No [162] => No [163] => $1.00 [164] => $0.01 [165] => N/A [166] => N/A [167] => No [168] => Yes DK [169] => Denmark [170] => 45 [171] => National [172] => Yes [173] => No [174] => No [175] => $1.00 [176] => $0.01 [177] => N/A [178] => N/A [179] => No [180] => No DO [181] => Dominican Republic [182] => 1809 [183] => Local [184] => Yes [185] => No [186] => No [187] => $7.00 [188] => $0.01 [189] => N/A [190] => N/A [191] => Yes [192] => No EE [193] => Estonia [194] => 372 [195] => National [196] => Yes [197] => No [198] => No [199] => $1.00 [200] => $0.01 [201] => N/A [202] => N/A [203] => Yes [204] => No ES [205] => Spain [206] => 34 [207] => Local [208] => Yes [209] => No [210] => No [211] => $1.00 [212] => $0.01 [213] => N/A [214] => N/A [215] => Yes [216] => Yes ES [217] => Spain [218] => 34 [219] => Local [220] => No [221] => Yes [222] => No [223] => $1.00 [224] => N/A [225] => $0.0075 [226] => N/A [227] => Yes [228] => No ES [229] => Spain [230] => 34 [231] => National [232] => Yes [233] => No [234] => No [235] => $1.00 [236] => $0.01 [237] => N/A [238] => N/A [239] => No [240] => No FI [241] => Finland [242] => 358 [243] => Local [244] => Yes [245] => No [246] => No [247] => $1.00 [248] => $0.01 [249] => N/A [250] => N/A [251] => Yes [252] => Yes FI [253] => Finland [254] => 358 [255] => Mobile [256] => No [257] => Yes [258] => No [259] => $1.00 [260] => N/A [261] => $0.0075 [262] => N/A [263] => Yes [264] => No FI [265] => Finland [266] => 358 [267] => National [268] => Yes [269] => No [270] => No [271] => $1.00 [272] => $0.01 [273] => N/A [274] => N/A [275] => No [276] => No FR [277] => France [278] => 33 [279] => National [280] => Yes [281] => No [282] => No [283] => $1.00 [284] => $0.01 [285] => N/A [286] => N/A [287] => No [288] => No GB [289] => United Kingdom [290] => 44 [291] => Local [292] => Yes [293] => Yes [294] => No [295] => $1.00 [296] => $0.01 [297] => $0.0075 [298] => N/A [299] => No [300] => No GB [301] => United Kingdom [302] => 44 [303] => Mobile [304] => No [305] => Yes [306] => No [307] => $1.00 [308] => N/A [309] => $0.0075 [310] => N/A [311] => Yes [312] => No GB [313] => United Kingdom [314] => 44 [315] => National [316] => Yes [317] => No [318] => No [319] => $1.00 [320] => $0.01 [321] => N/A [322] => N/A [323] => No [324] => No GB [325] => United Kingdom [326] => 44 [327] => Toll Free [328] => Yes [329] => No [330] => No [331] => $2.00 [332] => $0.06 [333] => N/A [334] => N/A [335] => No [336] => No GR [337] => Greece [338] => 30 [339] => Local [340] => Yes [341] => No [342] => No [343] => $1.00 [344] => $0.01 [345] => N/A [346] => N/A [347] => No [348] => Yes HK [349] => Hong Kong [350] => 852 [351] => National [352] => Yes [353] => No [354] => No [355] => $8.00 [356] => $0.01 [357] => N/A [358] => N/A [359] => No [360] => No IE [361] => Ireland [362] => 353 [363] => National [364] => Yes [365] => No [366] => No [367] => $1.00 [368] => $0.01 [369] => N/A [370] => N/A [371] => No [372] => No IL [373] => Israel [374] => 972 [375] => Local [376] => Yes [377] => No [378] => No [379] => $5.00 [380] => $0.01 [381] => N/A [382] => N/A [383] => No [384] => No IT [385] => Italy [386] => 39 [387] => Local [388] => Yes [389] => No [390] => No [391] => $1.00 [392] => $0.01 [393] => N/A [394] => N/A [395] => No [396] => No JP [397] => Japan [398] => 81 [399] => Local [400] => Yes [401] => No [402] => No [403] => $5.00 [404] => $0.01 [405] => N/A [406] => N/A [407] => No [408] => No LT [409] => Lithuania [410] => 370 [411] => Local [412] => Yes [413] => No [414] => No [415] => $1.00 [416] => $0.01 [417] => N/A [418] => N/A [419] => Yes [420] => No LU [421] => Luxembourg [422] => 352 [423] => Local [424] => Yes [425] => No [426] => No [427] => $3.00 [428] => $0.01 [429] => N/A [430] => N/A [431] => Yes [432] => Yes LV [433] => Latvia [434] => 371 [435] => Local [436] => Yes [437] => No [438] => No [439] => $1.00 [440] => $0.01 [441] => N/A [442] => N/A [443] => Yes [444] => Yes MT [445] => Malta [446] => 356 [447] => National [448] => Yes [449] => No [450] => No [451] => $5.00 [452] => $0.01 [453] => N/A [454] => N/A [455] => Yes [456] => No MX [457] => Mexico [458] => 52 [459] => Local [460] => Yes [461] => No [462] => No [463] => $3.00 [464] => $0.01 [465] => N/A [466] => N/A [467] => No [468] => Yes NL [469] => The Netherlands [470] => 31 [471] => National [472] => Yes [473] => No [474] => No [475] => $1.00 [476] => $0.01 [477] => N/A [478] => N/A [479] => No [480] => No NO [481] => Norway [482] => 47 [483] => Mobile [484] => No [485] => Yes [486] => No [487] => $4.00 [488] => N/A [489] => $0.0075 [490] => N/A [491] => Yes [492] => No NZ [493] => New Zealand [494] => 64 [495] => Local [496] => Yes [497] => No [498] => No [499] => $3.00 [500] => $0.01 [501] => N/A [502] => N/A [503] => No [504] => No PE [505] => Peru [506] => 51 [507] => Local [508] => Yes [509] => No [510] => No [511] => $5.00 [512] => $0.01 [513] => N/A [514] => N/A [515] => Yes [516] => No PL [517] => Poland [518] => 48 [519] => Local [520] => Yes [521] => No [522] => No [523] => $1.00 [524] => $0.01 [525] => N/A [526] => N/A [527] => No [528] => No PL [529] => Poland [530] => 48 [531] => Mobile [532] => No [533] => Yes [534] => No [535] => $1.00 [536] => N/A [537] => $0.0075 [538] => N/A [539] => Yes [540] => No PR [541] => Puerto Rico [542] => 1787 [543] => National [544] => Yes [545] => No [546] => No [547] => $8.00 [548] => $0.01 [549] => N/A [550] => N/A [551] => No [552] => No PT [553] => Portugal [554] => 351 [555] => National [556] => Yes [557] => No [558] => No [559] => $1.00 [560] => $0.01 [561] => N/A [562] => N/A [563] => No [564] => No RO [565] => Romania [566] => 40 [567] => Local [568] => Yes [569] => No [570] => No [571] => $5.00 [572] => $0.01 [573] => N/A [574] => N/A [575] => No [576] => Yes SE [577] => Sweden [578] => 46 [579] => Local [580] => Yes [581] => No [582] => No [583] => $1.00 [584] => $0.01 [585] => N/A [586] => N/A [587] => Yes [588] => Yes SE [589] => Sweden [590] => 46 [591] => Mobile [592] => No [593] => Yes [594] => No [595] => $1.00 [596] => N/A [597] => $0.0075 [598] => N/A [599] => Yes [600] => No SE [601] => Sweden [602] => 46 [603] => National [604] => Yes [605] => No [606] => No [607] => $1.00 [608] => $0.01 [609] => N/A [610] => N/A [611] => No [612] => No SK [613] => Slovakia [614] => 421 [615] => Local [616] => Yes [617] => No [618] => No [619] => $1.00 [620] => $0.01 [621] => N/A [622] => N/A [623] => No [624] => Yes SV [625] => El Salvador [626] => 503 [627] => Local [628] => Yes [629] => No [630] => No [631] => $10.00 [632] => $0.01 [633] => N/A [634] => N/A [635] => Yes [636] => No US [637] => United States [638] => 1 [639] => Local [640] => Yes [641] => Yes [642] => No [643] => $1.00 [644] => $0.01 [645] => $0.0075 [646] => N/A [647] => No [648] => No US [649] => United States [650] => 1 [651] => Toll Free [652] => Yes [653] => No [654] => No [655] => $2.00 [656] => $0.03 [657] => N/A [658] => N/A [659] => No [660] => No ZA [661] => South Africa [662] => 27 [663] => National [664] => Yes [665] => No [666] => No [667] => $1.00 [668] => $0.01 [669] => N/A [670] => N/A [671] => Yes [672] => No )
@prionkor
Copy link
Author

kallzu_parse_csv2() works perfectly. I wonder how to do it with WP HTTP API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment