当前位置:网站首页>[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';
}边栏推荐
- Oracle的md5
- The first game of the 11th provincial single chip microcomputer competition of the Blue Bridge Cup
- [mv-3d] - multi view 3D target detection network
- Global and Chinese markets for hand hygiene monitoring systems 2022-2028: Research Report on technology, participants, trends, market size and share
- The 11th Blue Bridge Cup single chip microcomputer provincial competition
- 蓝桥杯单片机第四届省赛
- VS2010插件NuGet
- Basic syntax of unity script (7) - member variables and instantiation
- MySQL index, transaction and storage engine
- The fourth provincial competition of Bluebridge cup single chip microcomputer
猜你喜欢

Gradle foundation | customize the plug-in and upload it to jitpack

潘多拉 IOT 开发板学习(RT-Thread)—— 实验1 LED 闪烁实验(学习笔记)

MySQL connection query and subquery

Blue Bridge Cup single chip microcomputer sixth temperature recorder

How to do medium and long-term stocks, and what are the medium and long-term stock trading skills?

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

One of the future trends of SAP ui5: embrace typescript

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

Account management of MySQL

The 10th Blue Bridge Cup single chip microcomputer provincial competition
随机推荐
Basic syntax of unity script (7) - member variables and instantiation
Get started with Aurora 8b/10b IP core in one day (5) -- learn from the official routine of framing interface
How to establish its own NFT market platform in 2022
Oracle 查看被锁的表和解锁
跳出舒适区,5年点工转型自动化测试工程师,我只用了3个月时间
Global and Chinese markets for infant care equipment, 2022-2028: Research Report on technology, participants, trends, market size and share
微信小程序中 在xwml 中使用外部引入的 js进行判断计算
一天上手Aurora 8B/10B IP核(5)----从Framing接口的官方例程学起
Class design basis and advanced
Global and Chinese market of gynaecological health training manikin 2022-2028: Research Report on technology, participants, trends, market size and share
[HCIA continuous update] overview of dynamic routing protocol
C#聯合halcon脫離halcon環境以及各種報錯解决經曆
蓝桥杯单片机省赛第十一届第一场
[designmode] builder model
MySQL index, transaction and storage engine
《MATLAB 神经网络43个案例分析》:第42章 并行运算与神经网络——基于CPU/GPU的并行神经网络运算
Didi open source Delta: AI developers can easily train natural language models
NLog use
蓝桥杯单片机省赛第九届
Kotlin基础学习 16