私人笔记PHP常用函数 - 自定义函数
Posted Rudon滨海渔村
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了私人笔记PHP常用函数 - 自定义函数相关的知识,希望对你有一定的参考价值。
<?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 二位数组按子数组某值排序
PHP:根据二维数组中的某个字段进行排序 - 申文哲 - 博客园首先了解下以下两个函数: 1.array_column() 返回输入数组中某个单一列的值。 2.array_multisort() 函数返回排序数组。您可以输入一个或多个数组。函数先对第一个数组进行排https://www.cnblogs.com/wenzheshen/p/9455554.html
PHP动态模板 ob_start 嵌套变量,foreach等
/**
* 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;
===================== 模板 =================
<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>
瀑布流 (直接看最下面的js部分)
https://www.cnblogs.com/mazey/p/15647609.htmlhttps://www.cnblogs.com/mazey/p/15647609.html
我改过的代码,看核心js即可(HTML参考上面的“PHP动态模板 ob_start 嵌套变量,foreach等”)
// https://www.cnblogs.com/mazey/p/15647609.html
//页面加载完之后再加载瀑布流
window.onload = function()
loadWaterfall('waterPool','waterBox');
//加载瀑布流函数
function loadWaterfall(boxID,thumbnailClass)
//获取装缩略图外部的盒子
var box = document.getElementById(boxID);
//获取装缩略图的数组
var thumbnail = box.getElementsByClassName(thumbnailClass);
//计算盒子内每行可以排列几个缩略图
var colCount = 3;
//创建放每次整理好的高度数组
var thumbnailHeightArr = [];
var spaceHeightBetween = 30; // px
// console.log(thumbnail.length);
for(var i = 0; i < thumbnail.length; i++)
// console.log(i);
//获取第一行高度数组
if(i < colCount)
thumbnailHeightArr.push(thumbnail[i].clientHeight);
// thumbnailHeightArr.push(thumbnail[i].offsetHeight);
// console.log(JSON.stringify(thumbnailHeightArr));
else
//获取之前最小高度
var minHeight = Math.min.apply(null,thumbnailHeightArr);
// console.log(JSON.stringify('Min height: '+minHeight));
//第一行最小高度索引
var minIndex = thumbnailHeightArr.indexOf(minHeight);
// console.log(JSON.stringify('Min index: '+minIndex));
//将此缩略图放在上面那行最小高度下面
thumbnail[i].style.position = 'absolute';
//距离顶部长度为这个缩略图上面那个缩略图的长度
let curHeightBegin = spaceHeightBetween + minHeight;
thumbnail[i].style.top = curHeightBegin + 'px';
//距离左边长度为这个缩略图上面那个缩略图距离左边的长度
thumbnail[i].style.left = thumbnail[minIndex].offsetLeft + 'px';
// col-sm-offset-1
thumbnail[i].classList.remove('col-sm-offset-1');
//更新最小高度
thumbnailHeightArr[minIndex] += thumbnail[i].offsetHeight;
// console.log(JSON.stringify(thumbnailHeightArr));
/* 父dom高度塌陷 - https://blog.csdn.net/wangjun5159/article/details/102527004 */
let currentMinHeight = Math.max.apply(null,thumbnailHeightArr) + 150;
box.style.minHeight = currentMinHeight + 'px';
以上是关于私人笔记PHP常用函数 - 自定义函数的主要内容,如果未能解决你的问题,请参考以下文章