Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Laravel中生成CSV之前删除html标记_Php_Laravel_Laravel 5 - Fatal编程技术网

Php 在Laravel中生成CSV之前删除html标记

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', '

我正在我的项目中使用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', '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()之后添加它