Skip to content

Instantly share code, notes, and snippets.

@codingfox-rus
codingfox-rus / PHP-mail-example.php
Last active August 29, 2015 14:02
PHP mail() example with attached file
<?php
# получаем данные и отсекаем пробельные символы в начале и конце:
$name = @ trim ($_POST['your-name']);
$email = @ trim ($_POST['your-email']);
$fileName = $_FILES['file-rezume']['name'];
if ( isset($_POST['your-message']) ) {
$userMessage = @ trim ($_POST['your-message']);
} else {
$userMessage = "";
}
@codingfox-rus
codingfox-rus / Time-counter.html
Last active August 29, 2015 14:05
Простейший счетчик обратного отсчета (дни-часы-минуты-секунды). Может использоваться в лендингах как заготовка
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Счетчик обратного отсчета</title>
<style>
#container {
margin: 0 auto;
width: 30%;
}
@codingfox-rus
codingfox-rus / getCookieName.js
Last active August 29, 2015 14:11
Получение куки по имени (JS)
function getCookie(name) {
var matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : undefined;
}
@codingfox-rus
codingfox-rus / validate_mobile_phone_number.php
Last active December 15, 2016 06:22
Валидация мобильного телефонного номера
<?php
/**
* @param $phone
* @return bool
*/
public function correctPhone($phone)
{
$phone = preg_replace('/[^0-9]/', '', trim($phone));
preg_match('/9[0-9]{9,9}/', $phone, $result);
@codingfox-rus
codingfox-rus / upload.php
Created August 2, 2015 13:14
Загрузчик картинок для CKEditor
<?php
function getex($filename) {
return end(explode(".", $filename));
}
if($_FILES['upload']) {
if (($_FILES['upload'] == "none") || (empty($_FILES['upload']['name'])) ) {
$message = "Вы не выбрали файл";
} else if ($_FILES['upload']["size"] == 0 || $_FILES['upload']["size"] > 2050000) {
@codingfox-rus
codingfox-rus / slice_array_of_sequences.php
Last active December 15, 2016 06:18
Алгоритм для разбиения массива по последовательностям чисел
<?php
$arr = [2,3,4,8,9,10,14,15,16,20,21,22];
// Вычисляем "пропуски" - индексы массива, на которых последовательность прерывается
$skips = [];
$start = $arr[0];
for ($i = 1; $i < sizeof($arr); $i++) {
if (($arr[$i] - $start) > 1) {
$skips[] = $i;
}