当前位置:网站首页>[personal notes] PHP common functions - custom functions
[personal notes] PHP common functions - custom functions
2022-07-02 03:39:00 【Rudon Binhai fishing village】

<?php
/* Common FN */
function check_is_https() {
if (isset($_SERVER["HTTPS"]) && strtolower($_SERVER['HTTPS']) != 'off') {
return true;
} elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') {
return true;
} elseif (isset($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) != 'off') {
return true;
} else {
return false;
}
}
function get_url_protocol_and_host() {
$p = check_is_https() ? 'https://' : 'http://';
return $p . $_SERVER['HTTP_HOST'] . '/';
}
/**
* get_list_of_folders_by_path_not_recursive
*
* @param string $dir
* @param type $sort
* @param type $except_hidden
* @return type
*/
function get_list_of_folders_by_path_not_recursive ($dir, $sort = 'ASC', $except_hidden = true) {
$return = array();
$dir = rtrim($dir, '/') . '/';
if (is_dir($dir)) {
$dh = opendir($dir);
while (($file = readdir($dh)) !== false) {
if (!in_array($file, array('.', '..'))) {
if (is_dir($dir . $file)) {
if(!$except_hidden){
$return[] = $file;
} elseif($except_hidden && preg_match('/^(?!\.)/', $file)) {
$return[] = $file;
} else {
}
}
}
}
closedir($dh);
}
if ($sort == 'DESC') {
arsort($return);
$return = array_values($return);
}
if ($sort == 'ASC') {
asort($return);
$return = array_values($return);
}
return $return;
}
/**
* get_list_of_files_by_path_not_recursive
*
* @param string $dir
* @param type $sort
* @param type $except_hidden
* @return type
*/
function get_list_of_files_by_path_not_recursive($dir, $sort = 'ASC', $except_hidden = true) {
$return = array();
$dir = rtrim($dir, '/') . '/';
if (is_dir($dir)) {
$dh = opendir($dir);
while (($file = readdir($dh)) !== false) {
if (!in_array($file, array('.', '..'))) {
if (is_file($dir . $file)) {
if(!$except_hidden){
$return[] = $file;
} elseif($except_hidden && preg_match('/^(?!\.)/', $file)) {
$return[] = $file;
} else {
}
}
}
}
closedir($dh);
}
if ($sort == 'DESC') {
arsort($return);
$return = array_values($return);
}
if ($sort == 'ASC') {
asort($return);
$return = array_values($return);
}
return $return;
}
function a ($v) {
header('Content-Type: text/css; charset=utf-8');
print_r($v);
die();
}
?>php A binary array is sorted by a value of a subarray
PHP: Sort according to a field in the two-dimensional array - Shenwenzhe - Blog Garden Let's first look at the following two functions : 1.array_column() Returns the value of a single column in the input array . 2.array_multisort() Function returns a sorted array . You can enter one or more arrays . Function first arranges the first array https://www.cnblogs.com/wenzheshen/p/9455554.html
PHP Dynamic templates ob_start Nested variables ,foreach etc.
/**
* component_tpl
*
*/
function component_tpl ($cName, $data = array()) {
$return = '';
$path = PATH_COMPONENTS . $cName . '.php';
ob_start();
$tpl_data = $data;
require $path;
$return = ob_get_contents();
ob_end_clean();
return $return;
}
===================== Templates =================
<div class="myWaterPool">
<div class="row" id="waterPool">
<?php foreach($tpl_data['apps'] as $k=>$v): ?>
<div class="col-sm-3 col-sm-offset-1 waterBox">
<a href="<?php echo $v['urlApp']; ?>" style="text-decoration: none; color: gray;">
<div>
<div class="text-center">
<?php echo $v['title']; ?>
</div>
<img src="<?php echo $v['urlPreview']; ?>" alt="" class="img-responsive myImg" style="border-radius: 14px;"/>
</div>
</a>
</div>
<?php endforeach; ?>
</div>
</div>
<div> </div>
<style>
#waterPool {
position: relative;
}
</style>
The waterfall flow ( Look directly at the bottom js part )
https://www.cnblogs.com/mazey/p/15647609.html
https://www.cnblogs.com/mazey/p/15647609.html
I changed the code , Look at the core js that will do (HTML Refer to the above “PHP Dynamic templates ob_start Nested variables ,foreach etc. ”)
// https://www.cnblogs.com/mazey/p/15647609.html
// After the page is loaded, load the waterfall flow
window.onload = function(){
loadWaterfall('waterPool','waterBox');
}
// Load waterfall stream function
function loadWaterfall(boxID,thumbnailClass){
// Get the box outside the thumbnail
var box = document.getElementById(boxID);
// Get the array of thumbnails
var thumbnail = box.getElementsByClassName(thumbnailClass);
// Several thumbnails can be arranged in each row of the calculation box
var colCount = 3;
// Create an array of heights to put each time
var thumbnailHeightArr = [];
var spaceHeightBetween = 30; // px
// console.log(thumbnail.length);
for(var i = 0; i < thumbnail.length; i++){
// console.log(i);
// Get the first row height array
if(i < colCount){
thumbnailHeightArr.push(thumbnail[i].clientHeight);
// thumbnailHeightArr.push(thumbnail[i].offsetHeight);
// console.log(JSON.stringify(thumbnailHeightArr));
}else{
// Get the previous minimum height
var minHeight = Math.min.apply(null,thumbnailHeightArr);
// console.log(JSON.stringify('Min height: '+minHeight));
// First row minimum height index
var minIndex = thumbnailHeightArr.indexOf(minHeight);
// console.log(JSON.stringify('Min index: '+minIndex));
// Place this thumbnail below the minimum height of the line above
thumbnail[i].style.position = 'absolute';
// The length from the top is the length of the thumbnail above this thumbnail
let curHeightBegin = spaceHeightBetween + minHeight;
thumbnail[i].style.top = curHeightBegin + 'px';
// The length from the left is the length from the left of the thumbnail above this thumbnail
thumbnail[i].style.left = thumbnail[minIndex].offsetLeft + 'px';
// col-sm-offset-1
thumbnail[i].classList.remove('col-sm-offset-1');
// Update minimum height
thumbnailHeightArr[minIndex] += thumbnail[i].offsetHeight;
// console.log(JSON.stringify(thumbnailHeightArr));
}
}
/* Father dom A high degree of collapse - https://blog.csdn.net/wangjun5159/article/details/102527004 */
let currentMinHeight = Math.max.apply(null,thumbnailHeightArr) + 150;
box.style.minHeight = currentMinHeight + 'px';
}边栏推荐
- Qt的网络连接方式
- C # joint Halcon's experience of breaking away from Halcon environment and various error reporting solutions
- Basic syntax of unity script (7) - member variables and instantiation
- leetcode-1380. Lucky number in matrix
- [C Advanced] brother Peng takes you to play with strings and memory functions
- MySQL connection query and subquery
- Kotlin基础学习 14
- 蓝桥杯单片机省赛第十一届第一场
- What is the binding path of SAP ui5
- 蓝桥杯单片机省赛第六届
猜你喜欢

Knowing things by learning | self supervised learning helps improve the effect of content risk control

The fourth provincial competition of Bluebridge cup single chip microcomputer

蓝桥杯单片机第六届温度记录器

焱融看 | 混合云时代下,如何制定多云策略

蓝桥杯单片机省赛第六届

ThreadLocal详解

The first game of the 12th Blue Bridge Cup single chip microcomputer provincial competition

【DesignMode】建造者模式(Builder model)

Generate random numbers that obey normal distribution

The 9th Blue Bridge Cup single chip microcomputer provincial competition
随机推荐
This article describes the step-by-step process of starting the NFT platform project
High performance and low power cortex-a53 core board | i.mx8m Mini
Global and Chinese markets for ultrasonic probe disinfection systems 2022-2028: Research Report on technology, participants, trends, market size and share
Screenshot literacy tool download and use
Failed to upgrade schema, error: “file does not exist
"Analysis of 43 cases of MATLAB neural network": Chapter 42 parallel operation and neural network - parallel neural network operation based on cpu/gpu
[designmode] builder model
The 9th Blue Bridge Cup single chip microcomputer provincial competition
Class design basis and advanced
Flutter中深入了解MaterialApp,常用属性解析
Network connection mode of QT
Blue Bridge Cup SCM digital tube skills
Detailed explanation of ThreadLocal
Comment élaborer une stratégie nuageuse à l'ère des nuages mixtes
Xlwings drawing
Didi open source Delta: AI developers can easily train natural language models
【DesignMode】建造者模式(Builder model)
MySQL advanced (Advanced) SQL statement (II)
Oracle viewing locked tables and unlocking
高性能 低功耗Cortex-A53核心板 | i.MX8M Mini