微擎生成公众号二维码 PHP

微擎生成公众号二维码(临时二维码)

$barcode = array(
    'expire_seconds' => 2592000,
    'action_name' => 'QR_STR_SCENE',
    'action_info' => array(
        'scene' => array(
            'scene_id'=>'100001',
            'scene_str' => '1_1'
        ),
    ),
);
$account_api = WeAccount::create();
$result = $account_api->barCodeCreateDisposable($barcode);
print_r($result);die;
//使用 即可

杨佳乐 发布于  2024-4-30 10:57 

php 生成随机邀请码 PHP

//随机生成邀请码
function getRandomString($len, $chars=null)
{
    if (is_null($chars)){
        $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    }

    for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++){
        $str .= $chars[mt_rand(0, $lc)];
    }
    return $str;
}

getRandomString(6); //生成6位随机邀请码

杨佳乐 发布于  2024-4-30 10:56 

MySQL FIND_IN_SET 函数使用 MySQL

FIND_IN_SET

有些文章存储标签使用 以下形式 1,2,3,4 可以使用改函数查询

select * from `test` where FIND_IN_SET('2',`字段名`);

杨佳乐 发布于  2024-4-30 10:55 

php phpOffice/PhpSpreadsheet 使用记录 PHP

<?php

//先自行使用composer下载phpoffice到项目文件夹
//官网地址:https://phpspreadsheet.readthedocs.io/en/latest/
//安装命令:composer require phpoffice/phpspreadsheet

//引入自动加载
require "./vendor/autoload.php";

//运行命名空间
use PhpOffice\PhpSpreadsheet;

//文件名
$inputFileName="1.xlsx";

//自动识别文件类型
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($inputFileName);
/**  Create a new Reader of the type that has been identified  **/
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
/**  Load $inputFileName to a Spreadsheet Object  **/
$spreadsheet = $reader->load($inputFileName);

//获取工作簿
$sheet=$spreadsheet->getActiveSheet();

//读取表格全部数据为数组
$sheetData = $sheet->toArray(null, true, true, true);

//获取单个单元格内容
$sheetvalue=$sheet->getCell('A1')->getValue();
$sheetvalue=$sheet->getCellByColumnAndRow(1,1)->getValue();

//设置单元格内容
$sheet->setCellValueByColumnAndRow(1,1,'2020级学生学号');

$sheet->setCellValue('A2', 'www.phpexcel.net');
//将上面单元格设置可点击的链接    注:网址需要加http://
$sheet->getCell('A2')->getHyperlink()->setUrl('http://www.phpexcel.net');

//设置工作簿标签颜色
//$sheet->getTabColor()->setRGB('F9F900');

//写入图片到单元格
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setName('Logo');
$drawing->setDescription('Logo');
$drawing->setPath('1.jpg');
//单元格坐标
$drawing->setCoordinates('A2');
//设置图片宽高
$drawing->setWidth(30);
$drawing->setHeight(30);
$drawing->setWorksheet($sheet);

//多个图片需用遍历new
/*for ($i=3;$i<=5;$i++){
    $drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
    $drawing->setName('Logo');
    $drawing->setDescription('Logo');
    $drawing->setPath('1.jpg');
    $drawing->setCoordinates('A'.$i);
    $drawing->setWidth(30);
    $drawing->setHeight(30);
    $drawing->setWorksheet($sheet);
}*/

$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('01simple.xlsx');

//写入文件到项目目录
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save("2.xlsx");

//下载文件
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');//告诉浏览器输出07Excel文件
//header(‘Content-Type:application/vnd.ms-excel‘);//告诉浏览器将要输出Excel03版本文件
header('Content-Disposition: attachment;filename="文档.xlsx"');//告诉浏览器输出浏览器名称
header('Cache-Control: max-age=0');//禁止缓存
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('php://output');

杨佳乐 发布于  2024-4-30 10:54 

php多维数组排序 PHP

//根据orderzmoney 降序排序 array_column 取出数组 orderzmoney字段数组
array_multisort(array_column($tylist,'orderzmoney'),SORT_DESC,$tylist);

杨佳乐 发布于  2024-4-30 10:51