Skip to content

Instantly share code, notes, and snippets.

Oleg Serebryakov Bandic00tt

Block or report user

Report or block Bandic00tt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View randomCCNumber.php
$numArr = [];
$numArr[] = rand(1000, 9999);
$numArr[] = rand(1000, 9999);
$numArr[] = rand(1000, 9999);
$numArr[] = rand(1000, 9999);
echo implode('', $numArr) . PHP_EOL;
View httpLogParser.php
<?php
mb_internal_encoding("UTF-8");
mb_regex_encoding('UTF-8');
$logPath = '';
$dbh = new PDO('mysql:host=localhost;dbname=log', 'root', 'password');
$handle = @fopen($logPath, "r");
@Bandic00tt
Bandic00tt / passgen.php
Created Sep 14, 2018
Генерация паролей в Codeigniter 3
View passgen.php
<?php
function get_password_hash($password)
{
$options = [
'salt' => random_string('alnum', 30),
'cost' => 10
];
return password_hash($password, PASSWORD_BCRYPT, $options);
}
View img-regexp.php
<?php
$html = '<div><img alt="" src="http://example.com/" alt="test"></div>';
$imgPattern = '/<img\s(.*)\/?>/U';
preg_match_all($imgPattern, $html, $matches, PREG_SET_ORDER);
$uId = 1;
foreach ($matches as $match) {
$img = trim($match[0]);
$attrContent = trim($match[1]);
@Bandic00tt
Bandic00tt / google-docs-to-html-fix.php
Last active Feb 6, 2018
Фикс при переводе дока из Google Docs в Html, для сохранения в БД через визуальный редактор (он режет некоторые теги)
View google-docs-to-html-fix.php
<?php
$html = file_get_contents('index.html');
$cssPattern = '/\.(c[0-9]+)\{(.*)\}/U';
preg_match_all($cssPattern, $html, $cssMatches, PREG_SET_ORDER);
$classPattern = '/\sclass=\"([A-Za-z0-9\s]+)\"/U';
preg_match_all($classPattern, $html, $classMatches, PREG_SET_ORDER);
foreach ($classMatches as $clMatch){
@Bandic00tt
Bandic00tt / pdo_example.php
Last active Sep 28, 2017
Образец соединения через PDO
View pdo_example.php
<?php
$host = '';
$db = '';
$user = '';
$pass = '';
$charset = 'utf8';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
@Bandic00tt
Bandic00tt / slice_array_of_sequences.php
Last active Dec 15, 2016
Алгоритм для разбиения массива по последовательностям чисел
View slice_array_of_sequences.php
<?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;
}
@Bandic00tt
Bandic00tt / upload.php
Created Aug 2, 2015
Загрузчик картинок для CKEditor
View upload.php
<?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) {
@Bandic00tt
Bandic00tt / validate_mobile_phone_number.php
Last active Dec 15, 2016
Валидация мобильного телефонного номера
View validate_mobile_phone_number.php
<?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);
You can’t perform that action at this time.