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 | |
$bom = pack('H*','EFBBBF'); | |
$json = preg_replace("/^$bom/", '', $json); |
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 | |
function format_phone($phone = '', $convert = false, $trim = true) { | |
if (empty($phone)) return ''; | |
$phone = preg_replace("/[^0-9A-Za-z]/", "", $phone); | |
if ($convert == true) { | |
$replace = array('2'=>array('a','b','c'),'3'=>array('d','e','f'),'4'=>array('g','h','i'),'5'=>array('j','k','l'),'6'=>array('m','n','o'),'7'=>array('p','q','r','s'),'8'=>array('t','u','v'), '9'=>array('w','x','y','z')); | |
foreach($replace as $digit=>$letters) { | |
$phone = str_ireplace($letters, $digit, $phone); | |
} | |
} |
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 | |
define ('SECRET', 'Your_secret_here'); | |
if (isset($_GET['challenge'])) { | |
echo $_GET['challenge']; | |
} else { | |
$raw_data = file_get_contents('php://input'); | |
if ($raw_data) { | |
$json = json_decode($raw_data); | |
if (is_object($json)) { |
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
function readCookie(name) { | |
var nameEQ = name + "="; | |
var ca = document.cookie.split(';'); | |
for(var i=0;i < ca.length;i++) { | |
var c = ca[i]; | |
while (c.charAt(0)==' ') c = c.substring(1,c.length); | |
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); | |
} | |
return null; | |
} |
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 | |
function locDistance($lat1, $lon1, $lat2, $lon2) { | |
$theta = $lon1 - $lon2; | |
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); | |
$dist = acos($dist); | |
$dist = rad2deg($dist); | |
$miles = $dist * 60 * 1.1515; | |
return ($miles * 1.609344 * 1000); |
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
-- 55.88846600 = current latitude | |
-- 37.44916300 = current longitude | |
SELECT Title, ROUND( 6371000 * acos( cos( radians('55.88846600') ) * cos( radians( Lat ) ) * cos( radians( Lng ) - radians('37.44916300') ) + sin( radians('55.88846600') ) * sin( radians( Lat ) ) ) ) AS distance FROM Points HAVING distance < 500 OR distance IS NULL ORDER BY distance LIMIT 1 |
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 | |
if (!function_exists('getallheaders')) { | |
function getallheaders() { | |
$headers = ''; | |
foreach ($_SERVER as $name => $value) { | |
if (substr($name, 0, 5) == 'HTTP_') { | |
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; | |
} | |
} |
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 | |
function ev_mb_ucfirst($str) { | |
$fc = mb_strtoupper(mb_substr($str, 0, 1)); | |
return $fc.mb_substr($str, 1); | |
} |
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 | |
function object_to_array($data) { | |
if (is_array($data) || is_object($data)) { | |
$result = array(); | |
foreach ($data as $key => $value) { $result[$key] = object_to_array($value); } | |
return $result; | |
} | |
return $data; | |
} |
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 | |
class db { | |
public $isConnected; | |
protected $datab; | |
public function __construct($username, $password, $host, $dbname, $options=array()){ | |
$this->isConnected = true; | |
try { | |
$this->datab = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options); | |
$this->datab->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
NewerOlder