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 | |
// gzip.php v1.2 - read http://rm.pp.ru/?1.phpgzip | |
// released on 2004-05-06, by Roman Mamedov<roman at rm.pp.ru> | |
// license: do with this code whatever you want. | |
///// Configuration ////////////////// | |
$PREFER_DEFLATE = false; // prefer deflate over gzip when both are supported | |
$FORCE_COMPRESSION = false; // force compression even when client does not report support | |
////////////////////////////////////// |
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 decided to create a singleton wrapper for PDO that ensures only one instance is ever used. | |
It uses PHP 5.3.0's __callStatic functionality to pass on statically called methods to PDO. | |
This means you can just call it statically from anywhere without having to initiate or define the object. | |
Usage examples: | |
<?php | |
DB::exec("DELETE FROM Blah"); |
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
public function buildQuery($query) | |
{ | |
$sql=isset($query['distinct']) && $query['distinct'] ? 'SELECT DISTINCT' : 'SELECT'; | |
$sql.=' '.(isset($query['select']) ? $query['select'] : '*'); | |
if(isset($query['from'])) | |
$sql.="\nFROM ".$query['from']; | |
else | |
throw new CDbException(Yii::t('yii','The DB query must contain the "from" portion.')); | |
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 timespan($time1, $time2 = NULL, $output = 'years,months,weeks,days,hours,minutes,seconds') | |
{ | |
$output = preg_split('/[^a-z]+/', strtolower((string) $output)); | |
if (empty($output)) | |
return FALSE; | |
extract(array_flip($output), EXTR_SKIP); | |
$time1 = max(0, (int) $time1); | |
$time2 = empty($time2) ? time() : max(0, (int) $time2); | |
$timespan = abs($time1 - $time2); | |
isset($years) and $timespan -= 31556926 * ($years = (int) floor($timespan / 31556926)); |
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 | |
/** | |
* Get Last Header (no need to follow by redirect manually) | |
* @param $url | |
* @return array | |
*/ | |
function getLastHeaderStatus($url) | |
{ | |
$result = array(); | |
$header = get_headers( $url, 1 ); |
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 | |
/** | |
* Generating Command Line Colors with PHP | |
* @author Mario Awad | |
* @link http://softkube.com/blog/generating-command-line-colors-with-php | |
*/ | |
function colorize($text, $status) { | |
$out = ""; | |
switch($status) { | |
case "SUCCESS": |
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
/** | |
* [CheckMemoryConsumption проверка занимаемой памяти приложением] | |
* @param string $state [состояние одно из возможных: initial,final,peak] | |
* @return string | |
*/ | |
public static function CheckMemoryConsumption($state = 'initial') | |
{ | |
$memorySizeConsumptionString = ''; | |
switch ($state){ |
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 | |
// декодим Unicode ( \xc3\xa9 ) | |
$a = array("\xc3\xa9"); | |
echo "Unicode: ", json_encode($a, JSON_UNESCAPED_UNICODE), "\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
/* Simple spam protection for email addresses using jQuery. | |
* Well, the protection isn’t jQuery-based, but you get the idea. | |
* This snippet allows you to slightly ‘obfuscate’ email addresses to make it harder for spambots to harvest them, while still offering a readable address to your visitors. | |
* E.g. | |
* <a href="mailto:foo(at)example(dot)com">foo at example dot com</a> | |
* → | |
* <a href="mailto:[email protected]">[email protected]</a> | |
*/ | |
$(function() { |
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 // got from here https://www.sanwebe.com/2011/02/how-to-detect-ajax-request-using-php | |
//detect ajax | |
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') { | |
die('Request must come from Ajax!'); | |
} |
OlderNewer