
php
php7.2报iconv_set_encoding(): Use of iconv.output_encoding is deprecated错误怎么解决?
博客 • taotao 发表了文章 • 0 个评论 • 1856 次浏览 • 2019-08-14 18:58
在php版本大于5.6以上的时候,以下的代码会报iconv_set_encoding(): Use of iconv.output_encoding is deprecated错误。
iconv_set_encoding(): Use of iconv.output_encoding is deprecated错误如何解决呢?用以下代码可以解决此错误。
if (PHP_VERSION_ID < 50600) {
iconv_set_encoding('input_encoding', 'UTF-8');
iconv_set_encoding('output_encoding', 'UTF-8');
iconv_set_encoding('internal_encoding', 'UTF-8');
} else {
ini_set('default_charset', 'UTF-8');
}
file_get_contents(): Unable to find the wrapper "
博客 • maomao 发表了文章 • 0 个评论 • 1214 次浏览 • 2019-06-03 10:57
两个解决方法:
一。要确保php.ini配置文件中,开启allow_url_fopen
二。开启php_openssl.dll扩展
通过以上两种方法就能解决这个错误。
php7.2 Warning: Use of undefined constant NONEXISTENT - assumed
博客 • maomao 发表了文章 • 0 个评论 • 1456 次浏览 • 2019-05-08 15:25
string(11) "NONEXISTENT"
解决方案:
不带引号的字符串是不存在的全局常量,转化成他们自身的字符串。 在以前,该行为会产生 E_NOTICE,但现在会产生 E_WARNING。在下一个 PHP 主版本中,将抛出 Error 异常。
php 7.3 Warning:count():Parameter must be an array or an object that impl
博客 • maomao 发表了文章 • 0 个评论 • 1236 次浏览 • 2019-04-14 16:32
在 PHP 7.2 中,用 count() 获取对象和数组的数量。如果对象不可数,PHP 会抛出警告⚠️ 。所以需要检查对象或者数组是否可数。 PHP 7.3 提供新的函数 is_countable() 来解决这个问题。
该 RFC 提供新的函数 is_countable(),对数组类型或者实现了
Countable接口的实例的变量返回 true 。
之前:
[code]if (is_array($foo) || $foo instanceof Countable) {[/code]
// $foo 是可数的
}
之后:
[code]if (is_countable($foo)) {[/code]
// $foo 是可数的
}
PHP网站页面跳转的几种方式
博客 • maomao 发表了文章 • 0 个评论 • 1248 次浏览 • 2019-04-14 15:58
第一种:通过JS使用windows.location.href=‘url’; 是页面自动跳转到新的地址
< ?php第二 种:header函数中Location类型的标头是一种特殊的header调用,常用来实现页面跳转。注意:
$url = "http://www.yunmasucai.com";
echo "< script language='javascript'
type='text/javascript'>";
echo "window.location.href='$url'";
echo "< /script>";
?>
注意:
1.header执行前不能有任何输出
2.location和:之间不能有空格
3.header后的php代码还会执行,所以需要注意使用exit;
<?php第三种:Meta标签是HTML中负责提供文档元信息的标签,在PHP程序中使用该标签,也可以实现页面跳转。 若定义http-equiv为refresh,则打开该页面时将根据content规定的值在一定时间内跳转到相应页面。
/* This will give an error. Note the output
* above, which is before the header() call */
header('Location: http://www.yunmasucai.com/');
exit;
?>
< meta http-equiv="refresh" content="1;url=http://www.yunmasucai.com">
支付宝支付 Deprecated:The each() function si deprecated
博客 • maomao 发表了文章 • 0 个评论 • 1574 次浏览 • 2019-04-14 12:21
支付宝支付的时候遇到的问题,这种是因为php7+以上版本抛弃了each函数导致
原函数如下:
/**修改成正确的如下:
* 除去数组中的空值和签名参数
* @param $para 签名参数组
* return 去掉空值与签名参数后的新签名参数组
*/
function paraFilter($para) {
$para_filter = array();
while (list ($key, $val) = each ($para)) {
if($key == "sign" || $key == "sign_type" || $val == "")continue;
else $para_filter[$key] = $para[$key];
}
return $para_filter;
}
function paraFilter($para) {
$para_filter = array();
foreach ($para as $key => $val) {
if($key == "sign" || $key == "sign_type" || $val == "")continue;
else $para_filter[$key] = $para[$key];
}
return $para_filter;
}
php手机号中间变星号****如何实现
博客 • maomao 发表了文章 • 0 个评论 • 1277 次浏览 • 2019-04-13 11:41
<?php结果如下:
$tel = '12345678910';
//1.字符串截取法
$new_tel1 = substr($tel, 0, 3).'****'.substr($tel, 7);
var_dump($new_tel1);
//2.替换字符串的子串
$new_tel2 = substr_replace($tel, '****', 3, 4);
var_dump($new_tel2);
//3.用正则
$new_tel3 = preg_replace('/(\d{3})\d{4}(\d{4})/', '$1****$2', $tel);
var_dump($new_tel3);
?>
> string(11) "123****8910"定义函数循环的方法:
> string(11) "123****8910"
> string(11) "123****8910"
$all_lottery_logs = ********; //该语句是得到中奖纪录
//遍历处理手机号
foreach($all_lottery_logs as $k=>$v){
$xing = substr($v['tel'],3,4); //获取手机号中间四位
$all_lottery_logs[$k]['tel'] = str_replace($xing,'****',$v['tel']); //用****进行替换
}
《全栈营销之如何制作个人博客》之五:广告位添加与调用 推荐文章数据调取
博客 • maomao 发表了文章 • 0 个评论 • 1439 次浏览 • 2019-03-19 21:10
首先我们在云码博客的后台添加10条左右的测试数据,thinkcmf后台添加文章的地方在门户管理-》文章管理,点击添加文章即可。添加完数据的效果如下图。
二.在博客后台添加广告位,在后台设置-》幻灯片管理,我们以首页为主,其他页面的广告位可以以些类推添加,首页大概有11处图片广告位置,我们以上部轮播图为例演示如何添加,调用动态广告。
后台添加完后,前台模板如何调用呢?下面我们看前台调用的程序代码如下:
运行的效果就和我们之前看过的静态模板页面一样,如下图所示。
三.头条推荐数据调用,在thinkcmf数据库中的文章存储在portal_post表中,有两个关键的字段来控制推荐和头条数据,推荐是recommended=1时,头条数据是is_top=1时。在后台设置就可以成为推荐和头条数据。
前端模板调用头条数据如何调用呢,具体的代码如下:
前端模板调用数据效果如下:
个人博客制作
我们的代码会共享出来,分享给大家。如果你获取完整的文字教程,视频教程,源码,关注公众号:云码素材,加微信:xnynews入群,和小伙伴一起学习,一起动手制作你的个人博客,一起探讨代码。

php二维数组排序自定义方法
博客 • maomao 发表了文章 • 0 个评论 • 1259 次浏览 • 2019-03-18 22:15
/**
* 二维数组根据字段进行排序
* @params array $array 需要排序的数组
* @params string $field 排序的字段
* @params string $sort 排序顺序标志 SORT_DESC 降序;SORT_ASC 升序
*/
function arraySequence($array, $field, $sort = 'SORT_DESC')
{
$sort = array(
'direction' => $sort, //排序顺序标志 SORT_DESC 降序;SORT_ASC 升序
'field' => $field, //排序字段
);
$arrSort = array();
foreach($array AS $uniqid => $row){
foreach($row AS $key=>$value){
$arrSort[$key][$uniqid] = $value;
}
}
if($sort['direction']){
array_multisort($arrSort[$sort['field']], constant($sort['direction']), $array);
}
return $array;
}
php图片搜索相似图片如何实现
博客 • taotao 发表了文章 • 0 个评论 • 1497 次浏览 • 2018-11-28 10:09
<?php方法二:
class ImageHash {
const FILE_NOT_FOUND = '-1';
const FILE_EXTNAME_ILLEGAL = '-2';
private function __construct() {}
public static function run($src1, $src2) {
static $self;
if(!$self) $self = new static;
if(!is_file($src1) || !is_file($src2)) exit(self::FILE_NOT_FOUND);
$hash1 = $self->getHashValue($src1);
$hash2 = $self->getHashValue($src2);
if(strlen($hash1) !== strlen($hash2)) return false;
$count = 0;
$len = strlen($hash1);
for($i = 0; $i < $len; $i++) if($hash1[$i] !== $hash2[$i]) $count++;
return $count <= 10 ? true : false;
}
public function getImage($file) {
$extname = pathinfo($file, PATHINFO_EXTENSION);
if(!in_array($extname, ['jpg','jpeg','png','gif'])) exit(self::FILE_EXTNAME_ILLEGAL);
$img = call_user_func('imagecreatefrom'. ( $extname == 'jpg' ? 'jpeg' : $extname ) , $file);
return $img;
}
public function getHashValue($file) {
$w = 8;
$h = 8;
$img = imagecreatetruecolor($w, $h);
list($src_w, $src_h) = getimagesize($file);
$src = $this->getImage($file);
imagecopyresampled($img, $src, 0, 0, 0, 0, $w, $h, $src_w, $src_h);
imagedestroy($src);
$total = 0;
$array = array();
for( $y = 0; $y < $h; $y++) {
for ($x = 0; $x < $w; $x++) {
$gray = (imagecolorat($img, $x, $y) >> 8) & 0xFF;
if(!isset($array[$y])) $array[$y] = array();
$array[$y][$x] = $gray;
$total += $gray;
}
}
imagedestroy($img);
$average = intval($total / ($w * $h * 2));
$hash = '';
for($y = 0; $y < $h; $y++) {
for($x = 0; $x < $w; $x++) {
$hash .= ($array[$y][$x] >= $average) ? '1' : '0';
}
}
var_dump($hash);
return $hash;
}
}
var_dump(ImageHash::run('./1.png', './psb.jpg'));
hash($f);调用方式如下:
}
return $isString ? $result[0] : $result;
}
public function checkIsSimilarImg($imgHash, $otherImgHash){
if (file_exists($imgHash) && file_exists($otherImgHash)){
$imgHash = $this->run($imgHash);
$otherImgHash = $this->run($otherImgHash);
}
if (strlen($imgHash) !== strlen($otherImgHash)) return false;
$count = 0;
$len = strlen($imgHash);
for($i=0;$i<$len;$i++){
if ($imgHash{$i} !== $otherImgHash{$i}){
$count++;
}
}
return $count <= (5 * $rate * $rate) ? true : false;
}
public function hash($file){
if (!file_exists($file)){
return false;
}
$height = 8 * $this->rate;
$width = 8 * $this->rate;
$img = imagecreatetruecolor($width, $height);
list($w, $h) = getimagesize($file);
$source = $this->createImg($file);
imagecopyresampled($img, $source, 0, 0, 0, 0, $width, $height, $w, $h);
$value = $this->getHashValue($img);
imagedestroy($img);
return $value;
}
public function getHashValue($img){
$width = imagesx($img);
$height = imagesy($img);
$total = 0;
$array = array();
for ($y=0;$y<$height;$y++){
for ($x=0;$x<$width;$x++){
$gray = ( imagecolorat($img, $x, $y) >> 8 ) & 0xFF;
if (!is_array($array[$y])){
$array[$y] = array();
}
$array[$y][$x] = $gray;
$total += $gray;
}
}
$average = intval($total / (64 * $this->rate * $this->rate));
$result = '';
for ($y=0;$y<$height;$y++){
for ($x=0;$x<$width;$x++){
if ($array[$y][$x] >= $average){
$result .= '1';
}else{
$result .= '0';
}
}
}
return $result;
}
public function createImg($file){
$ext = $this->getFileExt($file);
if ($ext === 'jpeg') $ext = 'jpg';
$img = null;
switch ($ext){
case 'png' : $img = imagecreatefrompng($file);break;
case 'jpg' : $img = imagecreatefromjpeg($file);break;
case 'gif' : $img = imagecreatefromgif($file);
}
return $img;
}
public function getFileExt($file){
$infos = explode('.', $file);
$ext = strtolower($infos[count($infos) - 1]);
return $ext;
}
}
require_once "Imghash.class.php";如果$result值为true, 则表明2个图片相似,否则不相似。
$instance = ImgHash::getInstance();
$result = $instance->checkIsSimilarImg('chenyin/IMG_3214.png', 'chenyin/IMG_3212.JPG');
php7.2报iconv_set_encoding(): Use of iconv.output_encoding is deprecated错误怎么解决?
博客 • taotao 发表了文章 • 0 个评论 • 1856 次浏览 • 2019-08-14 18:58
在php版本大于5.6以上的时候,以下的代码会报iconv_set_encoding(): Use of iconv.output_encoding is deprecated错误。
iconv_set_encoding(): Use of iconv.output_encoding is deprecated错误如何解决呢?用以下代码可以解决此错误。
if (PHP_VERSION_ID < 50600) {
iconv_set_encoding('input_encoding', 'UTF-8');
iconv_set_encoding('output_encoding', 'UTF-8');
iconv_set_encoding('internal_encoding', 'UTF-8');
} else {
ini_set('default_charset', 'UTF-8');
}
file_get_contents(): Unable to find the wrapper "
博客 • maomao 发表了文章 • 0 个评论 • 1214 次浏览 • 2019-06-03 10:57
两个解决方法:
一。要确保php.ini配置文件中,开启allow_url_fopen
二。开启php_openssl.dll扩展
通过以上两种方法就能解决这个错误。
php7.2 Warning: Use of undefined constant NONEXISTENT - assumed
博客 • maomao 发表了文章 • 0 个评论 • 1456 次浏览 • 2019-05-08 15:25
string(11) "NONEXISTENT"
解决方案:
不带引号的字符串是不存在的全局常量,转化成他们自身的字符串。 在以前,该行为会产生 E_NOTICE,但现在会产生 E_WARNING。在下一个 PHP 主版本中,将抛出 Error 异常。
php 7.3 Warning:count():Parameter must be an array or an object that impl
博客 • maomao 发表了文章 • 0 个评论 • 1236 次浏览 • 2019-04-14 16:32
在 PHP 7.2 中,用 count() 获取对象和数组的数量。如果对象不可数,PHP 会抛出警告⚠️ 。所以需要检查对象或者数组是否可数。 PHP 7.3 提供新的函数 is_countable() 来解决这个问题。
该 RFC 提供新的函数 is_countable(),对数组类型或者实现了
Countable接口的实例的变量返回 true 。
之前:
[code]if (is_array($foo) || $foo instanceof Countable) {[/code]
// $foo 是可数的
}
之后:
[code]if (is_countable($foo)) {[/code]
// $foo 是可数的
}
PHP网站页面跳转的几种方式
博客 • maomao 发表了文章 • 0 个评论 • 1248 次浏览 • 2019-04-14 15:58
第一种:通过JS使用windows.location.href=‘url’; 是页面自动跳转到新的地址
< ?php第二 种:header函数中Location类型的标头是一种特殊的header调用,常用来实现页面跳转。注意:
$url = "http://www.yunmasucai.com";
echo "< script language='javascript'
type='text/javascript'>";
echo "window.location.href='$url'";
echo "< /script>";
?>
注意:
1.header执行前不能有任何输出
2.location和:之间不能有空格
3.header后的php代码还会执行,所以需要注意使用exit;
<?php第三种:Meta标签是HTML中负责提供文档元信息的标签,在PHP程序中使用该标签,也可以实现页面跳转。 若定义http-equiv为refresh,则打开该页面时将根据content规定的值在一定时间内跳转到相应页面。
/* This will give an error. Note the output
* above, which is before the header() call */
header('Location: http://www.yunmasucai.com/');
exit;
?>
< meta http-equiv="refresh" content="1;url=http://www.yunmasucai.com">
支付宝支付 Deprecated:The each() function si deprecated
博客 • maomao 发表了文章 • 0 个评论 • 1574 次浏览 • 2019-04-14 12:21
支付宝支付的时候遇到的问题,这种是因为php7+以上版本抛弃了each函数导致
原函数如下:
/**修改成正确的如下:
* 除去数组中的空值和签名参数
* @param $para 签名参数组
* return 去掉空值与签名参数后的新签名参数组
*/
function paraFilter($para) {
$para_filter = array();
while (list ($key, $val) = each ($para)) {
if($key == "sign" || $key == "sign_type" || $val == "")continue;
else $para_filter[$key] = $para[$key];
}
return $para_filter;
}
function paraFilter($para) {
$para_filter = array();
foreach ($para as $key => $val) {
if($key == "sign" || $key == "sign_type" || $val == "")continue;
else $para_filter[$key] = $para[$key];
}
return $para_filter;
}
php手机号中间变星号****如何实现
博客 • maomao 发表了文章 • 0 个评论 • 1277 次浏览 • 2019-04-13 11:41
<?php结果如下:
$tel = '12345678910';
//1.字符串截取法
$new_tel1 = substr($tel, 0, 3).'****'.substr($tel, 7);
var_dump($new_tel1);
//2.替换字符串的子串
$new_tel2 = substr_replace($tel, '****', 3, 4);
var_dump($new_tel2);
//3.用正则
$new_tel3 = preg_replace('/(\d{3})\d{4}(\d{4})/', '$1****$2', $tel);
var_dump($new_tel3);
?>
> string(11) "123****8910"定义函数循环的方法:
> string(11) "123****8910"
> string(11) "123****8910"
$all_lottery_logs = ********; //该语句是得到中奖纪录
//遍历处理手机号
foreach($all_lottery_logs as $k=>$v){
$xing = substr($v['tel'],3,4); //获取手机号中间四位
$all_lottery_logs[$k]['tel'] = str_replace($xing,'****',$v['tel']); //用****进行替换
}
《全栈营销之如何制作个人博客》之五:广告位添加与调用 推荐文章数据调取
博客 • maomao 发表了文章 • 0 个评论 • 1439 次浏览 • 2019-03-19 21:10
首先我们在云码博客的后台添加10条左右的测试数据,thinkcmf后台添加文章的地方在门户管理-》文章管理,点击添加文章即可。添加完数据的效果如下图。
二.在博客后台添加广告位,在后台设置-》幻灯片管理,我们以首页为主,其他页面的广告位可以以些类推添加,首页大概有11处图片广告位置,我们以上部轮播图为例演示如何添加,调用动态广告。
后台添加完后,前台模板如何调用呢?下面我们看前台调用的程序代码如下:
运行的效果就和我们之前看过的静态模板页面一样,如下图所示。
三.头条推荐数据调用,在thinkcmf数据库中的文章存储在portal_post表中,有两个关键的字段来控制推荐和头条数据,推荐是recommended=1时,头条数据是is_top=1时。在后台设置就可以成为推荐和头条数据。
前端模板调用头条数据如何调用呢,具体的代码如下:
前端模板调用数据效果如下:
个人博客制作
我们的代码会共享出来,分享给大家。如果你获取完整的文字教程,视频教程,源码,关注公众号:云码素材,加微信:xnynews入群,和小伙伴一起学习,一起动手制作你的个人博客,一起探讨代码。

php二维数组排序自定义方法
博客 • maomao 发表了文章 • 0 个评论 • 1259 次浏览 • 2019-03-18 22:15
/**
* 二维数组根据字段进行排序
* @params array $array 需要排序的数组
* @params string $field 排序的字段
* @params string $sort 排序顺序标志 SORT_DESC 降序;SORT_ASC 升序
*/
function arraySequence($array, $field, $sort = 'SORT_DESC')
{
$sort = array(
'direction' => $sort, //排序顺序标志 SORT_DESC 降序;SORT_ASC 升序
'field' => $field, //排序字段
);
$arrSort = array();
foreach($array AS $uniqid => $row){
foreach($row AS $key=>$value){
$arrSort[$key][$uniqid] = $value;
}
}
if($sort['direction']){
array_multisort($arrSort[$sort['field']], constant($sort['direction']), $array);
}
return $array;
}
php图片搜索相似图片如何实现
博客 • taotao 发表了文章 • 0 个评论 • 1497 次浏览 • 2018-11-28 10:09
<?php方法二:
class ImageHash {
const FILE_NOT_FOUND = '-1';
const FILE_EXTNAME_ILLEGAL = '-2';
private function __construct() {}
public static function run($src1, $src2) {
static $self;
if(!$self) $self = new static;
if(!is_file($src1) || !is_file($src2)) exit(self::FILE_NOT_FOUND);
$hash1 = $self->getHashValue($src1);
$hash2 = $self->getHashValue($src2);
if(strlen($hash1) !== strlen($hash2)) return false;
$count = 0;
$len = strlen($hash1);
for($i = 0; $i < $len; $i++) if($hash1[$i] !== $hash2[$i]) $count++;
return $count <= 10 ? true : false;
}
public function getImage($file) {
$extname = pathinfo($file, PATHINFO_EXTENSION);
if(!in_array($extname, ['jpg','jpeg','png','gif'])) exit(self::FILE_EXTNAME_ILLEGAL);
$img = call_user_func('imagecreatefrom'. ( $extname == 'jpg' ? 'jpeg' : $extname ) , $file);
return $img;
}
public function getHashValue($file) {
$w = 8;
$h = 8;
$img = imagecreatetruecolor($w, $h);
list($src_w, $src_h) = getimagesize($file);
$src = $this->getImage($file);
imagecopyresampled($img, $src, 0, 0, 0, 0, $w, $h, $src_w, $src_h);
imagedestroy($src);
$total = 0;
$array = array();
for( $y = 0; $y < $h; $y++) {
for ($x = 0; $x < $w; $x++) {
$gray = (imagecolorat($img, $x, $y) >> 8) & 0xFF;
if(!isset($array[$y])) $array[$y] = array();
$array[$y][$x] = $gray;
$total += $gray;
}
}
imagedestroy($img);
$average = intval($total / ($w * $h * 2));
$hash = '';
for($y = 0; $y < $h; $y++) {
for($x = 0; $x < $w; $x++) {
$hash .= ($array[$y][$x] >= $average) ? '1' : '0';
}
}
var_dump($hash);
return $hash;
}
}
var_dump(ImageHash::run('./1.png', './psb.jpg'));
hash($f);调用方式如下:
}
return $isString ? $result[0] : $result;
}
public function checkIsSimilarImg($imgHash, $otherImgHash){
if (file_exists($imgHash) && file_exists($otherImgHash)){
$imgHash = $this->run($imgHash);
$otherImgHash = $this->run($otherImgHash);
}
if (strlen($imgHash) !== strlen($otherImgHash)) return false;
$count = 0;
$len = strlen($imgHash);
for($i=0;$i<$len;$i++){
if ($imgHash{$i} !== $otherImgHash{$i}){
$count++;
}
}
return $count <= (5 * $rate * $rate) ? true : false;
}
public function hash($file){
if (!file_exists($file)){
return false;
}
$height = 8 * $this->rate;
$width = 8 * $this->rate;
$img = imagecreatetruecolor($width, $height);
list($w, $h) = getimagesize($file);
$source = $this->createImg($file);
imagecopyresampled($img, $source, 0, 0, 0, 0, $width, $height, $w, $h);
$value = $this->getHashValue($img);
imagedestroy($img);
return $value;
}
public function getHashValue($img){
$width = imagesx($img);
$height = imagesy($img);
$total = 0;
$array = array();
for ($y=0;$y<$height;$y++){
for ($x=0;$x<$width;$x++){
$gray = ( imagecolorat($img, $x, $y) >> 8 ) & 0xFF;
if (!is_array($array[$y])){
$array[$y] = array();
}
$array[$y][$x] = $gray;
$total += $gray;
}
}
$average = intval($total / (64 * $this->rate * $this->rate));
$result = '';
for ($y=0;$y<$height;$y++){
for ($x=0;$x<$width;$x++){
if ($array[$y][$x] >= $average){
$result .= '1';
}else{
$result .= '0';
}
}
}
return $result;
}
public function createImg($file){
$ext = $this->getFileExt($file);
if ($ext === 'jpeg') $ext = 'jpg';
$img = null;
switch ($ext){
case 'png' : $img = imagecreatefrompng($file);break;
case 'jpg' : $img = imagecreatefromjpeg($file);break;
case 'gif' : $img = imagecreatefromgif($file);
}
return $img;
}
public function getFileExt($file){
$infos = explode('.', $file);
$ext = strtolower($infos[count($infos) - 1]);
return $ext;
}
}
require_once "Imghash.class.php";如果$result值为true, 则表明2个图片相似,否则不相似。
$instance = ImgHash::getInstance();
$result = $instance->checkIsSimilarImg('chenyin/IMG_3214.png', 'chenyin/IMG_3212.JPG');