Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8256989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:03:22+00:00 2026-06-08T02:03:22+00:00

I have one problem. I have excel file saved as CSV and I need

  • 0

I have one problem. I have excel file saved as CSV and I need to read that file with PHP and insert into mysql but problem is with char set specifically čćšđž. I tried utf8_encode() and almost everything I could think of.

Examle:

It inserts “Petroviæ” but it should be “Petrović”

EDIT:

<?php

mysql_connect("localhost", "user", "pw");  
mysql_select_db("database");  


$fajl = "Prodajna mreza.csv"; 
$handle = @fopen($fajl, "r");
if ($handle) {
    $size = filesize($fajl);

    if(!$size) {
        echo "File is empty.\n";
        exit;
    }

    $csvcontent = fread($handle,$size);
    $red = 1;

    foreach(explode("\n",$csvcontent) as $line) {
        if(strlen($line) <= 20)
        {
            $red++;
            continue;
        }
        if($red == 1)
        {
            $red++;
            continue;
        }
        $nesto = explode(",", $line);

        if($nesto[0] == '')
            continue;

        mysql_query("INSERT INTO table(val1, val2, val3, val4, val5, val6, val7, val8) VALUES ('".$nesto[0]."','".$nesto[1]."','".$nesto[2]."','".$nesto[3]."','".$nesto[4]."','".$nesto[5]."','".$nesto[6]."','".$nesto[7]."')");  

        $red++;
    }
    fclose($handle);
}
mysql_close();
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:03:24+00:00Added an answer on June 8, 2026 at 2:03 am

    First off: Using this mysql extension is discouraged. So you might want to switch to something else. Also notice that the way you compose your query by simply pasting strings makes it vulnerable to SQL injection attacks. You should only do this if you are really really sure that there won’t be any ugly surprises in the content of the files you read.

    It appears that neither your file reading nor the client-side mysql code does anything related to charset conversion, so I’d assume that those simply pass on bytes, without caring about their interpretation. So you only have to make sure that the server interprets those bytes correctly.

    Judging from the example you gave, where a ć got turned into an æ, I’d say your file is in ISO-8859-2 but the database is reading it differently, most probably as ISO-8859-1. You should ensure that your database actually can accept all ISO-8859-2 characters for its columns. Read the MySQL manual on character set support and set some suitable default characterset (probably best on the database level) either to utf8 (preferred) or latin2. You might have to recreate your tables for this change to apply.

    Next, you should set the character set of the connection to match that of the file. So utf8 is definitely wrong here, and latin2 the way to go.

    • Using your current API, mysql_set_charset("latin2") can be used to accomplish that.
    • That page also describes equivalent approaches for use with other frontends.
    • As an alternative, you can use a query to set this: mysql_query("SET NAMES ‘latin2’;");

    After all this is done, you should also ensure that things are set up correctly for any script which reads from the database. In other words, the charset of the generated HTML must match the character_set_results of the MySQL session. Otherwise it might well be that things are stored correctly in your database but still appear broken when displayed to the user. If you have the choice, I’d say use utf8 in that case, as doing so makes it easier to include different data whenever the need arises.

    If some problems remain, you should pinpoint whether they are while reading from file into php, while exchanging data with mysql, or while presenting the result in HTML. The string "Petrovi\xc4\x87" is the utf8 representation of your example, and "Petrovi\xe6" is the latin2 form. You can use these strings to explicitely pass on data with a known encoding, or to check an incoming transferred value against one of these strings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have wrote a code that can read an excel 2007 file using Microsoft
Basically my problem is this: I have a CSV excel file with info on
I facing a problem regarding the import of an excel file into mysql through
I have one problem , I want to get some data from XML file
i have one problem controlling checkbox, i'm reading, and searching about the topic but
I won't create wallpaper-application but have one problem. Please tell me how add ImageView
I have a C# program that maps legacy text file report to an excel
I have an excel file with 815 records that includes service name and charge.
I have a simple report that I want to export to a CSV file.
I have another puzzling problem. I need to read .xls files with RODBC. Basically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.