4

I am trying to read a .csv file and use its data after, but when I use the text that I am getting from this file it is coming with some "question marks in black diamonts" where it is suppose to have some special chars, like "á", "ú".

I thought that maybe the text from the .csv file was in a different encoding, but I did a mb_detect_encoding and it showed that it was UTF-8

This is the code I am using now:

<html>
<head>
    <meta charset="utf-8">
</head>
<body>

<?php

$row = 1;
$handle = fopen ("Exportar.csv","r");

$url = array();
$text1 = array();
$text2 = array();
$title = array();
$subtitle = array();
$description = array();
$image = array();

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $num = count ($data);
    if ($row > 1) {
        $url[$row -2 ] = $data[2];
        echo $text1[$row -2] = $data[6];
        //echo $encode = mb_detect_encoding($text1[$row -2]);
        $text2[$row -2] = $data[7];
        $title[$row -2] = $data[8];
        $subtitle[$row -2] = $data[9];
        $description[$row -2] = $data[10];
        $image[$row -2] = $data[11];
    }
    $row++;
}
fclose ($handle);


// Rest of the code....

?>

And this is the output:

Vimos que voc� n�o realizou nenhum pedido em nosso site nos �ltimos 90 dias. Para o seu pr�ximo pedido, ganhe 15% de desconto em todo o site!

user3697768
  • 359
  • 1
  • 7
  • 18
  • Tons of duplicate questions for this, voted to close [check this question](http://stackoverflow.com/questions/5445137/utf-8-encoded-html-pages-show-%EF%BF%BD-questions-marks-instead-of-characters) – Elias Van Ootegem Jul 06 '14 at 15:54

1 Answers1

2

HTML isn't able to read the special characters by itself. You'll need to convert them to to the HTML entities, such as &aacute;. Look at the htmlentities function.

Something like this:

<?php
   $str = 'é, í, ó, ú, ü, ñ';
   echo htmlentities($str, ENT_IGNORE , "ISO-8859-1");
?>
matt
  • 121
  • 4
  • I tried to do that, but when I use the text on my application, is goes like this: Vimos que você não realizou nenhum pedido em nosso site nos últimos 90 dias. Para o seu próximo pedido, ganhe 15% de desconto em todo o site! – user3697768 Jul 06 '14 at 21:05