// 加载文件
$spreadsheet = IOFactory::load($attachment);
// 读取内容
$sheetData = $spreadsheet->getSheet(0)->toArray(null, true, true, true);
// 循环检查数据
$allData = [];
$allError = [];
foreach ($sheetData as $key => $val) {
if ($key == 1) {
continue;
}
// 跳过空行
$val = array_map('trim', $val); // 去除首尾空格
if (empty(array_filter($val))) {
continue;
}
try {
$allData[] = $this->checkAndConvertItem($val);
} catch (\Exception $exception) {
$error = '第A' . $key . '行,此题需要检查,' . $exception->getMessage();
$allError[] = $error;
}
}通过array_filter过滤即可
function objtoarr($obj){ $ret = array(); foreach($obj as $key =>$value){ if(gettype($value) == 'arr...
逛公众号文章看到文章"php实现事件监听与触发的方法,你用过吗?",我就好奇了,php又不是asp.net的webform,哪里来的服务端事件监听。于是学习了一波。先看下监听类:class Event { /** &nbs...
<?php $member = new class { public function getInfo() { ...
今天帮朋友查询wordpress执行超级慢的原因,特此记录开启fpm的慢日志,记录执行超过30秒的脚本request_slowlog_timeout = 30 slowlog = var/log/slow.log查看日志[23-May-2019 17...
有时候我们需要爬一个接口,但是这个接口需要很多参数,包括header和cookie要去编写,使用php curl模拟实在太慢。我们可以通过浏览器的network来复制请求为curl命令。例如我需要模拟请求接口地址:https://www.xkmz.cc/Ajax/Debug/delly,我们只需要在...
使用openssl扩展对应替换mcrypt的函数,(比较麻烦,但是openssl是未来趋势)在新版php中编译mcrypt扩展使用一个纯php代码实现的mcrypt扩展库,git地址为https://github.com/phpseclib/mcrypt_compat,每个mcrypt的方法都已经实...