Search code examples
phplaravellaravel-excel

How to avoid special characters with Laravel Excel?


I'm trying to upload an excel file... but my string contains this special character "°" how could avoid it to upload into my database?

use Maatwebsite\Excel\Concerns\WithHeadingRow;
class IncidenciasImport implements OnEachRow, WithHeadingRow
{
      public function onRow(Row $row)
      {  
      $row = $row->toArray();
      $incidencias = Incidencias::firstOrCreate([
            'nro_ticket_prov' => $row['n_ticket_proveedor'],
      ]);
}
}

Solution

  • I am not sure if it is the best solution but you could simply use the strg_replace function. The first argument is what you are searching for in this case "°", with the second arguments you say "replace it with this string". And the third argument is your object in which you want to replace it.

    So in your case it may look something like this:

    str_replace('"°"', '', $row['n_ticket_proveedor']);
    

    This would replace it with an empty string.

    But in your case I would check what "°" stand for in excel and replace it properly.