Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iconv suddenly returns question marks, what am I doing wrong?

Tags:

php

iconv

The iconv code that I have, worked yesterday perfectly. Today it suddenly shows those question marks at the parts that should be translated(�).

setlocale(LC_ALL, 'nl_NL');
    $title = str_replace(' & ', ' & ', $feed[$x]['title']);
    $title = (iconv('UTF-8', 'ISO-8859-1//TRANSLIT//IGNORE', $title));
    $link = $feed[$x]['link'];
    $description = $feed[$x]['desc'];
    $description = (iconv('UTF-8', 'ISO-8859-1//TRANSLIT//IGNORE', $description));
    $datedag = date('d', strtotime($feed[$x]['date']));
    $datemaand = date('F', strtotime($feed[$x]['date']));
    $datejaar = date('Y', strtotime($feed[$x]['date']));
    echo '<div style="border:1px solid black;background-color:#d90000;"><p><strong><a href="'.$link.'" title="'.$title.'" target="_blank">'.$title.'</a></strong><br />';
    echo '<small><em>Geplaatst op '.$datedag.' '.$datemaand.', '.$datejaar.'</em></small></p>';
    echo '<p>'.$description.'</p></div><br />';

Now, I didnt add the setlocale until the question marks showed up, but it had no succes.

Question: What am I doing wrong?

like image 984
Stefan Teunissen Avatar asked Feb 12 '23 11:02

Stefan Teunissen


2 Answers

This worked for me

setlocale(LC_ALL, 'en_US.UTF-8');

although my language was Czech. Credit to Stone

like image 182
Josef Habr Avatar answered Feb 15 '23 00:02

Josef Habr


It happened to me that the encoding was wrong since I updated PHP to 5.6. This version sets the default charset to UTF-8 and transports this via the HTTP-Header, even though you set your charset to ISO-8859-1 in your HTML meta-tag.

Consider using UTF-8 at all or overrule the default charset by including the following line at the beginning of your script:

ini_set('default_charset', '');

You can also change the default charset in your php.ini as well.

like image 21
Jay Dinse Avatar answered Feb 14 '23 23:02

Jay Dinse