3月 20, 2023 - laravel    Laravel6 export customize data to excel file.已关闭评论

Laravel6 export customize data to excel file.

使用composer包工具:maatwebsite/excel

"maatwebsite/excel": "^3.1

步骤:

1:先定义一个export的Object

<?php

namespace App\Imports;

use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Imports\HeadingRowFormatter;

HeadingRowFormatter::default('none');

class UsersImport implements FromA[......]

Read more

3月 3, 2023 - php开发    php解析url的参数已关闭评论

php解析url的参数

想要解析一个url的参数.可以采用parse_url+parse_str的结合来完成:示例:

$a = 'https://staging.ivi.cn?expires_in=2023-03-04 11:01:42&jwt_token=eyJ0eXAiOiJKV1QiLCJhb';
parse_str(parse_url($a)['query'], $result_arr);

$result_arr结果如下:

array:2 [
"expires_in" => "2023-03-04 11:01:42"
 "jwt_token" => "eyJ0eXAiOiJKV[......]

Read more

1月 17, 2023 - laravel, php开发    php调用ChatGPT示例已关闭评论

php调用ChatGPT示例

用Laravel调用示例,官方文档链接:

https://platform.openai.com/docs/api-reference/completions/create

让ChatGPT做首诗:
$open_ai_key = env('OPENAI_API_KEY', 'the open api key');
$client = new Client(['verify' => false]);
$query = [
    'model' => 'text-davinci-003',
    'prompt' => '写一首诗',
    't[......]

Read more

页面:«1...9101112131415...42»