当前位置:网站首页>[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.htmlhttps://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';
}
边栏推荐
- Uniapp uses canvas to generate posters and save them locally
- How to establish its own NFT market platform in 2022
- 蓝桥杯单片机省赛第十一届第二场
- 初识string+简单用法(二)
- 傅里叶级数
- js生成随机数
- 蓝桥杯单片机省赛第十二届第一场
- [HCIA continuous update] overview of dynamic routing protocol
- NLog use
- Basic syntax of unity script (8) - collaborative program and destruction method
猜你喜欢
The 9th Blue Bridge Cup single chip microcomputer provincial competition
Review materials of project management PMP high frequency examination sites (8-1)
The 7th Blue Bridge Cup single chip microcomputer provincial competition
Exchange rate query interface
[mv-3d] - multi view 3D target detection network
Kubernetes cluster storageclass persistent storage resource core concept and use
Interface debugging tool simulates post upload file - apipost
Account management of MySQL
[HCIA continuous update] working principle of OSPF Protocol
一文彻底理解评分卡开发中——Y的确定(Vintage分析、滚动率分析等)
随机推荐
Basic syntax of unity script (8) - collaborative program and destruction method
Didi open source Delta: AI developers can easily train natural language models
Oracle common SQL
Uniapp uses canvas to generate posters and save them locally
Grpc quick practice
Kotlin basic learning 17
蓝桥杯单片机省赛第十二届第一场
VS2010 plug-in nuget
Generate random numbers that obey normal distribution
In depth analysis of C language - variable error prone knowledge points # dry goods inventory #
Global and Chinese market of X-ray detectors 2022-2028: Research Report on technology, participants, trends, market size and share
The 10th Blue Bridge Cup single chip microcomputer provincial competition
The 6th Blue Bridge Cup single chip microcomputer provincial competition
What kind of interview is more effective?
Screenshot literacy tool download and use
[untitled] basic operation of raspberry pie (2)
One of the future trends of SAP ui5: embrace typescript
This article describes the step-by-step process of starting the NFT platform project
[yolo3d]: real time detection of end-to-end 3D point cloud input
蓝桥杯单片机省赛第十一届第二场