This file contains 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 formatCurrencySign($price, $currency, $separator = "") | |
{ | |
if (!in_array($currency, array('USD', 'GBP', 'EUR'))) | |
{ | |
return $price . $separator . $currency; | |
} | |
switch ($currency) | |
{ | |
case 'USD': | |
$format = "$" . $separator . $price; |
This file contains 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 | |
// you can choose from MySQL and SQLite | |
define('DB_DRIVER', 'mysql'); | |
// SQLite don't use host parameter | |
define('DB_HOST', 'localhost'); | |
define('DB_USER', 'login'); | |
define('DB_PASS', 'password'); | |
// In case of SQLite usage, change it to path/to/your.db, for example | |
define('DB_NAME', 'testdb'); |
This file contains 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 convertLinks($text) { | |
$text = preg_replace('/(((f|ht){1}tps?:\/\/)[-a-zA-Z0-9@:;%_\+.~#?&\/\/=]+)/', '<a href="\\1" target="_blank">\\1</a>', $text); | |
$text = preg_replace('/([[:space:]()[{}])(www.[-a-zA-Z0-9@:;%_\+.~#?&\/\/=]+)/', '\\1<a href="http://\\2" target="_blank">\\2</a>', $text); | |
$text = preg_replace('/(([0-9a-zA-Z\.\-\_]+)@([0-9a-zA-Z\.\-\_]+)\.([0-9a-zA-Z\.\-\_]+))/', '<a href="mailto:$1">$1</a>', $text); | |
return $text; | |
} |
This file contains 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 whois_query($domain) { | |
// fix the domain name: | |
$domain = strtolower(trim($domain)); | |
$domain = preg_replace('/^http:\/\//i', '', $domain); | |
$domain = preg_replace('/^www\./i', '', $domain); | |
$domain = explode('/', $domain); | |
$domain = trim($domain[0]); | |
// split the TLD from domain name |
This file contains 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
echo "Initial: ".memory_get_usage()." bytes \n"; | |
/* prints | |
Initial: 361400 bytes | |
*/ | |
// let's use up some memory | |
for ($i = 0; $i < 100000; $i++) { | |
$array []= md5($i); | |
} |
This file contains 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
$i = imagecreatefromjpeg("image.jpg"); | |
for ($x=0;$x<imagesx($i);$x++) { | |
for ($y=0;$y<imagesy($i);$y++) { | |
$rgb = imagecolorat($i,$x,$y); | |
$r = ($rgb >> 16) & 0xFF; | |
$g = ($rgb >> & 0xFF; | |
$b = $rgb & 0xFF; | |
$rTotal += $r; |
This file contains 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
$lines = file('http://google.com/'); | |
foreach ($lines as $line_num => $line) { | |
// loop thru each line and prepend line numbers | |
echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . " | |
\n"; | |
} |
This file contains 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 detect_city($ip) { | |
$default = 'UNKNOWN'; | |
if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost') | |
$ip = '8.8.8.8'; | |
$curlopt_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)'; | |
$url = 'http://ipinfodb.com/ip_locator.php?ip=' . urlencode($ip); |
This file contains 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 ordinal($cdnl){ | |
$test_c = abs($cdnl) % 10; | |
$ext = ((abs($cdnl) %100 < 21 && abs($cdnl) %100 > 4) ? 'th' | |
: (($test_c < 4) ? ($test_c < 3) ? ($test_c < 2) ? ($test_c < 1) | |
? 'th' : 'st' : 'nd' : 'rd' : 'th')); | |
return $cdnl.$ext; | |
} |
This file contains 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 get_client_language($availableLanguages, $default='en'){ | |
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { | |
$langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']); | |
foreach ($langs as $value){ | |
$choice=substr($value,0,2); | |
if(in_array($choice, $availableLanguages)){ | |
return $choice; | |
} | |
} | |
} |