PHP 学习笔记

# 常用技巧

# 发送GET请求

$html = file_get_contents($url);
$file = fopen($url, 'r');
stream_get_meta_data($file);
while(!feof($file)) {
  $html .= fgets($file, 1024);
}
fclose($file);

# 发送POST请求

$data = http_build_query([]);
$options = [
  'http' => [
    'method' => 'POST',
    'header' => 'Content-type: application/x-www-form-urlencodedrn ' . 'Content-Length: ' . strlen($data) . "/r/n",
    'content' => $data,
  ],
];
$context = stream_context_create($options);
$html = file_get_contents($url, false, $context);

# 匿名函数传参

$func = function() use ($parameter) {
  var_dump($parameter);
};

# 删除文件

$ok = unlink($path);

# 判断对象是否存在

$existed = function_exists($function_name); # 判断存在 函数
$existed = class_exists($class_name); # 判断存在 类
$existed = method_exists($object, $method_name); # 判断存在 方法
$existed = property_exists($object, $property_name); # 判断存在 对象

# 获取运行参数

echo $argc; # 参数数量
echo $argv; # 参数数组

# 常用库

# Word
composer require phpoffice/phpspreadsheet
# Excel
composer require phpoffice/phpword

# Composer镜像

$ composer config -g [url] composer
$ composer clearcache
$ composer update || install
https://mirrors.aliyun.com/composer/ # 阿里
https://mirrors.cloud.tencent.com/composer/ # 腾讯
https://mirrors.huaweicloud.com/repository/php/ # 华为
https://packagist.phpcomposer.com/
https://packagist.mirrors.sjtug.sjtu.edu.cn/

# 常用工具

  • phpMyAdmin
  • phpPgAdmin
  • Adminer
  • WordPress
  • Discuz

版权协议