当前位置:网站首页>[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';
}边栏推荐
- Didi open source Delta: AI developers can easily train natural language models
- PY3 link MySQL
- Knowing things by learning | self supervised learning helps improve the effect of content risk control
- Halcon image rectification
- 微信小程序中 在xwml 中使用外部引入的 js进行判断计算
- [database]jdbc
- Kubernetes cluster storageclass persistent storage resource core concept and use
- This article describes the step-by-step process of starting the NFT platform project
- Global and Chinese markets for hand hygiene monitoring systems 2022-2028: Research Report on technology, participants, trends, market size and share
- 蓝桥杯单片机省赛第九届
猜你喜欢

【直播回顾】战码先锋首期8节直播完美落幕,下期敬请期待!

Yan Rong looks at how to formulate a multi cloud strategy in the era of hybrid cloud

接口调试工具模拟Post上传文件——ApiPost

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

Pointer array & array pointer

Which of PMP and software has the highest gold content?

One of the future trends of SAP ui5: embrace typescript

High performance and low power cortex-a53 core board | i.mx8m Mini

蓝桥杯单片机第四届省赛

MySQL connection query and subquery
随机推荐
[punch in] flip the string (simple)
高性能 低功耗Cortex-A53核心板 | i.MX8M Mini
[untitled] basic operation of raspberry pie (2)
Knowing things by learning | self supervised learning helps improve the effect of content risk control
NLog use
Halcon image rectification
Imageai installation
Fourier series
The fourth provincial competition of Bluebridge cup single chip microcomputer
Kubernetes cluster storageclass persistent storage resource core concept and use
In the era of programmers' introspection, five-year-old programmers are afraid to go out for interviews
Kotlin basic learning 13
[designmode] Prototype Pattern
《MATLAB 神經網絡43個案例分析》:第42章 並行運算與神經網絡——基於CPU/GPU的並行神經網絡運算
Kotlin基础学习 14
Global and Chinese market of X-ray detectors 2022-2028: Research Report on technology, participants, trends, market size and share
Kotlin 基础学习13
蓝桥杯单片机省赛第十二届第一场
Class design basis and advanced
PY3 link MySQL