dtv55860
dtv55860
2017-11-15 20:44

特殊字符法国口音

  • php
  • mysql

We are fetching data from csv file through php, and trying to compare data to insert the right data in our database but php comparison is not working as data in file is with french accents.

Here is a piece of code we are working with.

if($data[0]=='Expression' && $data[1]=='Domaine (Domain)' &&  utf8_decode($data[2])==utf8_decode('DŽfinition (Definition)') && $data[3]=='Commentaire (Commentary)' && $data[4]=='Voir aussiÉ (See also É)' && $data[5]=='ƒquivalent anglais (English equivalent)' && $data[6]=='En contexte / exemple(s) É (In context / examples)' && $data[7]=='Source' )
     {
                 echo "<tr>
                      <td>".$data['0']."</td>
                      <td>".$data['1']."</td>
                      <td>".$data['2']."</td>
                      <td>".$data['3']."</td>
                      <td>".$data['4']."</td>
                      <td>".$data['5']."</td>
                      <td>".$data['6']."</td>
                      <td>".$data['7']."</td>
                      <td><i class='fa fa-close text-navy'></i></td>
                    </tr>";
         return true;
     }
     else
     {
         echo "invalid data";
         exit;
     }

We have tried with this as well.

function convert($data)
{
    $value = utf8_encode($data);
    $value = iconv('UTF-8', 'ASCII//TRANSLIT', $value);
    return $value;
}

Header is already placed output is fine

header('Content-Type: text/html; charset=iso-8859-1');

We have tried with several php functions like utf_decode,html entities, html special char, htmlspecialchar_decode but nothing is working.

echo print_r(utf8_decode($data[2]));

output is as following:

D?finition (Definition)1invalid data

Actual word is : DŽfinition (Definition)'

We are working on french dictionary and need to do real time searching on the data as well, please help with mysql as well, like which functions are needed to be called before insertion for decoding and which functions are needed to be called before showing data back to user encoding!

Hope my question is bit clear.

Thanks in advance

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐