Skip to content

Instantly share code, notes, and snippets.

@Itachi261092
Itachi261092 / prgrsbr.php
Last active September 7, 2018 20:52
This is simpliest progress-bar for php scripts
function prgrsbr($oneStep, $maxSteps){
$percent = $oneStep / $maxSteps * 100;
$width = $percent * 10; // CSS property. 1% = 10px / 100% = 1000px
echo '<div style="width:1000px;height:40px;border:1px solid black;"><div style="width:'.$width.'px;height:40px;line-height:40px;background-color:green;text-align:center">'.$percent.'%</div></div>';
}
$iMax = 10000;
for ($i = 1; $i <= $iMax; $i++) {
prgrsbr($i, $iMax);
}
<?php
// функция для безопасности строк
function safestr($str){
$str = trim($str);
$str = stripslashes($str);
$str = htmlspecialchars($str);
return $str;
}
// проверка корректности полученных данных
function testFields($fields){
@Itachi261092
Itachi261092 / script.php
Created February 21, 2018 13:41
Посчитать расстояние между 2 точками координат
$R = 6371; // Earth radius in km
$dLat = (($q[0] - $p[0]) * pi() / 180);
$dLon = (($q[1] - $p[1]) * pi() / 180);
$a = sin($dLat / 2) * sin($dLat / 2) +
cos($p[0] * pi() / 180) * cos($q[0] * pi() / 180) *
sin($dLon / 2) * sin($dLon / 2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
return $R * $c;
@Itachi261092
Itachi261092 / parser.php
Created September 18, 2017 08:26
xml to array parse
foreach (scandir(_FOLDER) as $xmlFile) {
if (!is_dir(_FOLDER . $xmlFile)) {
$xml = simplexml_load_file(_FOLDER . $xmlFile);
$array = json_decode(json_encode($xml), true);
}
}
@Itachi261092
Itachi261092 / urlrewrite.php
Created January 27, 2017 08:57
URL rewrite for bitrix
// Initialize
$context = Bitrix\Main\Context::getCurrent();
$server = $context->getServer();
$server_array = $server->toArray();
// Скармливаем URL. Установить GET-параметры
$server_array['REQUEST_URI'] = $_SERVER['REQUEST_URI'] . $type . implode('&', $str);
$server->set($server_array);
$context->initialize(new Bitrix\Main\HttpRequest($server, array(), array(), array(), $_COOKIE), $context->getResponse(), $server);
@Itachi261092
Itachi261092 / README.md
Created January 28, 2016 14:24
[JS] Input file preview without load on server / input file превью без загрузки картинки на сервер
@Itachi261092
Itachi261092 / parse_youtube.php
Created October 13, 2015 11:57
[PHP] Youtube links parser / Парсер ютуб ссылок
if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match)) {
$video_id = $match[1];
}
@Itachi261092
Itachi261092 / .htaccess
Created October 13, 2015 07:27
[HTACCESS] Replace "*/index.php" or "*/index" URL to "*/" / Замена урлов сайта
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/index$ [OR]
RewriteCond %{REQUEST_URI} ^/index[.]+(\w+)$
RewriteRule . / [R=301,L]
@Itachi261092
Itachi261092 / getapatch.php
Created October 12, 2015 13:00
[PHP] Get absolute web-server path / Получаем абсолютный путь к веб-серверу
<?php
echo 'Document root: '.$_SERVER['DOCUMENT_ROOT'].'<br>';
echo 'Полный путь к скрипту и его имя: '.$_SERVER['SCRIPT_FILENAME'].'<br>';
echo 'Имя скрипта: '.$_SERVER['SCRIPT_NAME'];
?>
@Itachi261092
Itachi261092 / header.html
Created October 6, 2015 14:31
[HTML] HTML5 favicon.png
<!-- FAVICON -->
<link rel="icon" type="image/png" href="/favicon.png" />
<!-- for apple main style-->
<!--link rel="apple-touch-icon" href="apple-touch-favicon.png"/-->
<!-- for apple precomposed-->
<link rel="apple-touch-icon-precomposed" href="/apple-touch-favicon.png"/>