php - 在 Laravel 中生成 CSV 之前删除 html 标签
问题描述
我在我的项目中使用 Laravel 5.8。
我有这个代码:
class ExportEvents extends Model
{
use scopeActiveTrait;
protected $quarded = ['id'];
protected $fillable = ['title', 'title_on_the_list', 'content', 'date_from', 'hour_from', 'date_to', 'hour_to', 'price', 'responsible_person', 'phone_responsible_person', 'www_responsible_person', 'email_responsible_person'];
public $timestamps = false;
protected $table = "event_calendars";
}
use Maatwebsite\Excel\Excel;
public function downloadData(string $type = 'csv')
{
$data = ExportEvents::get()->toArray();
$fileName = 'Events '.now();
return \Excel::create($fileName, function ($excel) use ($data) {
$excel->sheet('mySheet', function ($sheet) use ($data) {
$sheet->fromArray($data);
});
})->download($type);
}
}
此代码工作正常,但我必须从我的 csv 文件中的“内容”列中删除 html 标记。
我怎样才能做到这一点?
解决方案
在生成 Excel 文档之前,您需要对数据进行预处理。请参阅此示例代码。
foreach($data as $i => $item){
$content = strip_tags($item['content']);
$data[$i]['content'] = $content;
}
推荐阅读
- python - 我们可以在不使用 Python 函数的情况下创建本地环境吗?
- javascript - React - map 函数仅使用数组中的最后一项设置输入值
- matlab - MATLAB-从以波形为参考的给定连续波形中识别附加峰值
- java - 将 IntelliJ 项目从 Windows 桌面移动到 Linux Mint 笔记本电脑,现在类类型变量的类型错误
- spring - 与具有嵌套数组的请求主体签订合同
- node.js - 防止自动重定向并获取 PassportJs "authenticate" 方法的重定向 URL
- android - Android:Kotlin 从回调中获取数据并随流发出
- go - 信号量的并发限制,为什么我必须先释放缓冲区?
- r - data.matrix vs data.frame 和 data.matrix vs as.matrix
- javascript - 即使 Safari Web Inspector 没有显示任何错误,JavaScript 代码也不会运行