PHP: Undefined index even if it exists

后端 未结 6 770
难免孤独
难免孤独 2021-01-18 03:22

It drives me crazy ... I try to parse a csv file and there is a very strange behavior.

Here is the csv

action;id;nom;sites;heures;jours
i;;\"un nom a         


        
6条回答
  •  伪装坚强ぢ
    2021-01-18 03:55

    Probably there is some special character at the beginning of the first line and trim isn't removing it.

    Try to remove every non-word character this way:

    // Identify headers
    if(!isset($headers))
    {
        for($i=0;$i<$cols;$i++)
        {
            $headers[preg_replace("/[^\w\d]/","",strtolower($row[$i]))] = $i;
    ....
    

提交回复
热议问题