Php 在Laravel中生成CSV之前删除html标记
我正在我的项目中使用Laravel5.8 我有以下代码:Php 在Laravel中生成CSV之前删除html标记,php,laravel,laravel-5,Php,Laravel,Laravel 5,我正在我的项目中使用Laravel5.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', '
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;
}
我可以在哪里添加它?在
$data=ExportEvents::get()->toArray()之后添加它代码>