如何在下载期间删除csv文件中的html代码之间的空格


How to remove spaces between html code in csv file during download time

我想删除adv_text字段中的空格。它包含HTML代码,因此出现了很多空格。在下载之前,我想删除空格

public function downloadadv()
{
    $today_date = date('Y-m-d');
    $this->load->helper('download');
    $this->load->dbutil(); 
    $this->load->model('admin/adv_model');  
    $query=$this->adv_model->advdetail(); 
    foreach($query->result() as $name) 
    {
        $text=replace($name->adv_text,' ','');
        echo $text;
    }
}

在这里下载之前,我使用替换,但没有效果。

要删除字符串中多次出现的空白字符并将它们全部转换为单个空格,请使用preg_replace:

$text = $name->adv_text;
$text = preg_replace('/'s+/', ' ', $text);//Remove space and tab.

参考:http://php.net/manual/en/function.trim.php

如果只是空格,使用str_replace:

$text = $name->adv_text;
$text = str_replace(' ', '', $text);//Remove only spaces

str_replace()代替replace()