Skip to content

Instantly share code, notes, and snippets.

Avatar

Oleg Serebryakov Bandic00tt

View GitHub Profile
@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 / 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){
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 / 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 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");
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;
You can’t perform that action at this time.