This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// TSV to Array Function | |
// Copyright (c) 2015, Ink Plant | |
// https://inkplant.com/code/ | |
// this version was last updated June 23, 2015 | |
function tsv_to_array($file,$args=array()) { | |
//key => default | |
$fields = array( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert data in CSV (comma separated value) format to a javascript array. | |
* | |
* Values are separated by a comma, or by a custom one character delimeter. | |
* Rows are separated by a new-line character. | |
* | |
* Leading and trailing spaces and tabs are ignored. | |
* Values may optionally be enclosed by double quotes. | |
* Values containing a special character (comma's, double-quotes, or new-lines) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$formaction = $_SERVER['PHP_SELF']; //the URL the form should send users to on submit | |
$allowedfiletypes = array('csv'); //a comma separated list of allowed extensions | |
$uploadfolder = './'; //the folder where the uploaded file should be moved to | |
$uploadfilename = 'data.csv'; //the filename that the uploaded file should be renamed to | |
//check to see if the form has been submitted | |
if (array_key_exists('action',$_POST) && is_string($_POST['action']) && (strip_tags($_POST['action']) == 'upload')) { //the form has been submitted | |
echo '<p>Uploading file... '; | |
if (empty($_FILES['uploadfile']['name'])) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://inkplant.com/code/get-timezone | |
<?php | |
function get_timezone($latitude,$longitude,$username) { | |
//error checking | |
if (!is_numeric($latitude)) { custom_die('A numeric latitude is required.'); } | |
if (!is_numeric($longitude)) { custom_die('A numeric longitude is required.'); } | |
if (!$username) { custom_die('A GeoNames user account is required. You can get one here: http://www.geonames.org/login'); } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://inkplant.com/code/ipv6-to-number | |
<?php | |
function ipaddress_to_ipnumber($ipaddress) { | |
$pton = @inet_pton($ipaddress); | |
if (!$pton) { return false; } | |
$number = ''; | |
foreach (unpack('C*', $pton) as $byte) { | |
$number .= str_pad(decbin($byte), 8, '0', STR_PAD_LEFT); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://inkplant.com/code/spell-numbers | |
<?php | |
function spellnumber($x,$min=0,$max=100) { | |
if (!preg_match('/^-?([0-9]{1,15})(\.[0-9]+)?$/',$x)) { return $x; } //if not a number less than a quadrillion, leave it alone | |
elseif (strpos($x,'.') !== false) { list($int,$dec) = explode('.',$x); return number_format($int).'.'.$dec; } //if not an intenger | |
elseif (($min !== false) && ($x < $min)) { return number_format($x); } //return numeral if less than minimum | |
elseif (($max !== false) && ($x > $max)) { return number_format($x); } //return numeral if greater than maximum | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://inkplant.com/code/csv-to-mysql | |
<?php | |
// CSV to MySQL Function | |
// Copyright (c) 2015, Ink Plant | |
// this version was last updated November 6, 2015 | |
// https://inkplant.com/code/csv-to-mysql | |
ini_set('auto_detect_line_endings',true); | |
function csv_to_mysql($args=array()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// CSV to Array Function | |
// Copyright (c) 2014-2015, Ink Plant | |
// https://inkplant.com/code/csv-to-array | |
// this version was last updated July 20, 2015 | |
ini_set('auto_detect_line_endings',true); | |
function csv_to_array($file,$args=array()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://inkplant.com/code/custom-die | |
<?php | |
function custom_die($args=false,$h1=false,$show_header=true,$show_footer=true) { | |
//note: if $args comes in as a string, it is actually $args['error'] | |
//this lets you access the function in shorthand | |
if (!is_array($args)) { $args = array('error'=>$args); } | |
//get all the options set |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Array to CSV Function | |
// Copyright (c) 2014-2016, Ink Plant | |
// https://inkplant.com/code/array-to-csv | |
// last updated May 10, 2016 | |
function array_to_csv($data,$args=false) { | |
if (!is_array($args)) { $args = array(); } | |
foreach (array('download','line_breaks','return','trim') as $key) { |