// 加载文件
$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过滤即可
逛公众号文章看到文章"php实现事件监听与触发的方法,你用过吗?",我就好奇了,php又不是asp.net的webform,哪里来的服务端事件监听。于是学习了一波。先看下监听类:class Event { /** &nbs...
ThinkPHP中有一个debug调试功能,能输出报错文件的信息,并能看到这个函数被哪些函数调用,从框架的启动开始记录,特别方便调试。于是研究了下它的底层给予了实现。<?php //--框架核心--Start //框架内置错误处理 function errDealWith($er...
<?php /** * @throws Exception */ function curl() { throw new \Exception('err...
经常我们下载国外资源容易被墙,可以通过php脚本获取远程文件流然后输出给我们的浏览器来下载。<?php //设置下载文件的url $url = 'https://mirrors.huaweicloud.com/ubuntukylin/ubuntukylin-19....
断点下载的原理:http请求头添加Range参数告诉文件服务器端需要的字节范围例如1个文本文件的字节为1000,第一次请求Range: bytes=0-500第二次请求Range: bytes=501-1000通过每次的请求将返回的流追加写入到文件。注意的项目:断点下载服务器端的每次只返回字节传输的...
【一】.基本用法首先看看官方对send方法的解释:Sets the return value of the yield expression and resumes the generato...