PHP Importing CSV files getting strange characters

I am importing csv files and storing them in my database.

The problem is that I am getting some strange characters when I try to use var_dump

.

Here is a picture of these symbols:

enter image description here

In CSV it doesn't look like it looks like it is 13.05.2014 17

So, obviously something is wrong.

So my question is, how do I remove all these strange characters?

Your help would be greatly appreciated!

Thank!:)

+3


source to share


1 answer


You must first check your character set and then convert it. You can use mb_detect_encoding ($ of); if you don't know the character set. However, in general it will always be one of them: UTF-8, ASCII, ISO-8859-1, ISO-8859-15 In most cases, the result should be UTF-8. You should adapt this PHP code to your needs. PHP module mb_string is required. Otherwise, you must replace it with another conversion function.



$out = 'some strange character set @@@@@@@@@';
if (
    function_exists('mb_detect_encoding') &&
    is_callable('mb_detect_encoding')
) {
    $charset = mb_detect_encoding($out, 'UTF-8,ASCII,ISO-8859-1,ISO-8859-15', TRUE);
}

if (
    $charset != '' &&
    $charset != 'UTF-8'
) {
    $out =
        mb_convert_encoding(
            $out,
            'UTF-8',
            $charset
        );
}

var_dump($out);

      

+1


source







All Articles