当前位置:网站首页>[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';
}边栏推荐
- The 9th Blue Bridge Cup single chip microcomputer provincial competition
- Unity脚本的基础语法(7)-成员变量和实例化
- The second game of the 11th provincial single chip microcomputer competition of the Blue Bridge Cup
- Basic syntax of unity script (8) - collaborative program and destruction method
- Kubernetes cluster storageclass persistent storage resource core concept and use
- 一天上手Aurora 8B/10B IP核(5)----从Framing接口的官方例程学起
- ThreadLocal详解
- [golang] leetcode intermediate bracket generation & Full Permutation
- Download and use of the super perfect screenshot tool snipaste
- KL divergence is a valuable article
猜你喜欢

Eight steps of agile development process

This article describes the step-by-step process of starting the NFT platform project

Flutter中深入了解MaterialApp,常用属性解析

0 foundation how to learn automated testing? Follow these seven steps step by step and you will succeed

Fourier series

The 8th Blue Bridge Cup single chip microcomputer provincial competition

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

一文彻底理解评分卡开发中——Y的确定(Vintage分析、滚动率分析等)

NLog use
![[designmode] builder model](/img/e8/855934d57eb6868a4d188b2bb1d188.png)
[designmode] builder model
随机推荐
Kotlin基础学习 14
PY3 link MySQL
The 7th Blue Bridge Cup single chip microcomputer provincial competition
What is the binding path of SAP ui5
The second game of the 12th provincial single chip microcomputer competition of the Blue Bridge Cup
一天上手Aurora 8B/10B IP核(5)----从Framing接口的官方例程学起
近段时间天气暴热,所以采集北上广深去年天气数据,制作可视化图看下
蓝桥杯单片机省赛第十届
Unity脚本的基础语法(6)-特定文件夹
初识string+简单用法(二)
Oracle 常用SQL
0基础如何学习自动化测试?按照这7步一步一步来学习就成功了
Eight steps of agile development process
Global and Chinese markets for ultrasonic probe disinfection systems 2022-2028: Research Report on technology, participants, trends, market size and share
蓝桥杯单片机省赛第十一届第一场
[punch in] flip the string (simple)
《MATLAB 神经网络43个案例分析》:第41章 定制神经网络的实现——神经网络的个性化建模与仿真
In depth analysis of C language - variable error prone knowledge points # dry goods inventory #
ThreadLocal详解
The 8th Blue Bridge Cup single chip microcomputer provincial competition