event.stopPropagation();
document.body.addEventListener('click', () => {
if (newdiw.classList.contains("active")) newdiw.classList.remove("active");
});
unwrap();
- убивает родителя, но при этом сохраняет детей.clid.unwrap();
function isBot(&$botname = ''){
/* Эта функция будет проверять, является ли посетитель роботом поисковой системы */
$bots = array(
'rambler','googlebot','aport','yahoo','msnbot','turtle','mail.ru','omsktele',
'yetibot','picsearch','sape.bot','sape_context','gigabot','snapbot','alexa.com',
'megadownload.net','askpeter.info','igde.ru','ask.com','qwartabot','yanga.co.uk',
'scoutjet','similarpages','oozbot','shrinktheweb.com','aboutusbot','followsite.com',
'dataparksearch','google-sitemaps','appEngine-google','feedfetcher-google',
'liveinternet.ru','xml-sitemaps.com','agama','metadatalabs.com','h1.hrn.ru',
'googlealert.com','seo-rus.com','yaDirectBot','yandeG','yandex',
'yandexSomething','Copyscape.com','AdsBot-Google','domaintools.com',
'Nigma.ru','bing.com','dotnetdotcom'
);
foreach($bots as $bot)
if(stripos($_SERVER['HTTP_USER_AGENT'], $bot) !== false){
$botname = $bot;
return true;
}
return false;
}
if( isBot($bname) ) {
// Перебрасываем на Москву
}
$array = [
0 => ['a' => 1, 'b' => 2, 'c' => 3],
1 => ['a' => 1, 'b' => 3, 'c' => 3],
2 => ['a' => 1, 'b' => 2, 'c' => 4],
3 => ['a' => 1, 'b' => 2, 'c' => 3],
];
$keys = array_keys($array[0]);
$keys = array_filter(
$keys,
function($key) use($array) {
count(array_unique(array_column($array, $key);)) > 1;
}
);
$array = array_map(
function($el) use($keys) {
return array_filter(
$el,
function($key) use($keys) {
return in_array($key, $keys);
},
ARRAY_FILTER_USE_KEY
);
},
$array
);
print_r($array);
/*
Array (
[0] => Array (
[b] => 2
[c] => 3
)
[1] => Array (
[b] => 3
[c] => 3
)
[2] => Array (
[b] => 2
[c] => 4
)
[3] => Array (
[b] => 2
[c] => 3
)
)
/*
crypto.createHash('sha1').update(str).digest('latin1'); // raw_output
crypto.createHash('sha1').update(str).digest('base64'); // сразу base64
async function sha1(str) {
const buf = Uint8Array.from(unescape(encodeURIComponent(str)), c=>c.charCodeAt(0)).buffer;
const digest = await crypto.subtle.digest('SHA-1', buf);
const raw = String.fromCharCode.apply(null, new Uint8Array(digest));
return raw; // 20-символьная строка
// или
return btoa(raw); // base64
}
function getPromise() {
return new Promise((resolve, reject) => {
setTimeout(() => resolve('готово'), 1000);
});
}
async function asyncCall() {
for (let i=0; i < 100; i++) {
console.log(await getPromise());
}
}
$a = 'test';
class Cls {
public function __construct($a) {
global $a;
$this->a = $a;
}
public function printer(){
global $a;
echo $this->a;
}
}
$get = new Cls($a);
$get->printer();
function next_seq() {
static id=0;
return id++;
}
function yoyo() {
static $o=false;
if($o===false) $o=new MyCoolObject();
return $o;
}
использовать:
yoyo()->myCoolMethod();
<?php
$a = 'test';
class Cls {
public function __construct($a) {
$this->a = $a;
}
public function printer(){
echo $this->a;
}
}
$get = new Cls($a);
$get->printer();