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 | |
//взято отсюда https://habr.com/sandbox/75204/ | |
//проверка заголовков https://last-modified.com | |
$LastModified_unix = $timetime; // время последнего изменения страницы | |
$LastModified = gmdate(«D, d M Y H:i:s \G\M\T», $LastModified_unix); | |
$IfModifiedSince = false; | |
if (isset($_ENV['HTTP_IF_MODIFIED_SINCE'])) | |
$IfModifiedSince = strtotime(substr($_ENV['HTTP_IF_MODIFIED_SINCE'], 5)); | |
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) |
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
/** | |
* Обрезает строку до определённого количества символов не разбивая слова. | |
* Поддерживает многобайтовые кодировки. | |
* @param string $str строка | |
* @param int $length длина, до скольки символов обрезать | |
* @param string $postfix постфикс, который добавляется к строке | |
* @param string $encoding кодировка, по-умолчанию 'UTF-8' | |
* @return string обрезанная строка | |
*/ |
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 | |
// взято отсюда http://www.realcoding.net/articles/keshirovanie-stranits-v-php.html | |
/* | |
require_once("/cache.php"); //Подключаем класс | |
$new=new CACHE; //Объявляем класс | |
$new->cache_content();//Буферизируем контент файла | |
$new->haupt_cache(); | |
?> | |
*/ |
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 | |
define('LNGtranslit1','а,б,в,г,д,е,ё,ж,з,и,й,к,л,м,н,о,п,р,с,т,у,ф,х,ц,ч,ш,ы,ь,щ,ъ,э,ю,я'); | |
define('LNGtranslit2','a,b,v,g,d,e,yo,j,z,i,iy,k,l,m,n,o,p,r,s,t,u,f,h,c,ch,sh,y,,sh,,e,yu,ya'); | |
function translit($string,$max=60) { | |
$string=mb_strtolower($string,'UTF-8'); | |
$d1=explode(',',LNGtranslit1); | |
$d2=explode(',',LNGtranslit2); | |
$string=str_replace($d1,$d2,$string); | |
$d1=array(' ',',','&','і'); | |
$d2=array('-','-','-and-','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
<?php | |
$testUrl = 'http://www.domain.ru/dir/dir?u=test'; | |
if( preg_match('/^(http|https|ftp):\/\/([A-Z0-9])[A-Z0-9_-]*(\.?[A-Z0-9]+)+?/iU', $testUrl ) ) echo 'yes'; else echo 'no'; | |
?> |
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 | |
//database connect | |
define('DB_NAME', 'demo'); | |
define('DB_USER', 'demo'); | |
define('DB_PASSWORD', 'demo'); | |
define('DB_HOST', 'localhost'); | |
$link = mysqli_connect(DB_HOST, DB_USER , DB_PASSWORD, DB_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
<script> | |
// На сервер будет отправлен запрос страницы http://hostname/ajaxtest.php и указаны два параметра. | |
// После получения ответа от сервера будет вызвана функция onAjaxSuccess, которая выведет | |
// на экран сообщение с данными, присланными сервером. | |
$.get( | |
"http://meteo4.com/1day.php", | |
{ | |
param1: "param1", | |
param2: 2 |
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 words_limit($input_text, $limit = 50, $end_str = '') { | |
$input_text = strip_tags($input_text); | |
$words = explode(' ', $input_text); // создаём из строки массив слов | |
if ($limit < 1 || sizeof($words) <= $limit) { // если лимит указан не верно или количество слов меньше лимита, то возвращаем исходную строку | |
return $input_text; | |
} | |
$words = array_slice($words, 0, $limit); // укорачиваем массив до нужной длины | |
$out = implode(' ', $words); |