Jump to content

Baltas

Members
  • Posts

    12
  • Joined

  • Last visited

Everything posted by Baltas

  1. Yes, your case is working.. But I've got no ideas where is the problem in my case : ) Even strange things happen.. when I try to export data straight from the phpMyAdmin (!) WHY like that even from database?!
  2. Now. I suppose I understood that obvious mistake with fetching text from the DB, so I change it to mysql_set_charset('UTF-8',$dbc); //because data is saved as UTF-8 in the database??? First of all, I'm converting the text from ASCII to ISO-8859-13 (ref. http://php.net/manual/en/function.mb-convert-encoding.php). Secondly, I used this line: $word = mb_detect_encoding($row[$j]); to have a look what is the type of encoding of that text fetching from the database. This shows me: As we can see encoding type is ASCII. Therefore, I was using that conversion function (from ASCII to ISO-8859-13): $out = mb_convert_encoding($str, "ISO-8859-13", "ASCII"); Then, if I don't use any conversions excel file refuses those characters...
  3. OK. Now my code looks like that: <?php $DB_TBLName = "reg_form"; $filename = "excelfile"; $dbc = mysql_connect('localhost', 'user', 'pass') or die('Error connecting to MySQL server.'); $db_name = mysql_select_db('database', $dbc); mysql_set_charset('ISO-8859-13',$dbc); $query = "SELECT first_name AS 'Vardas Pavardė', age AS 'Amžius', etc. etc. etc. from $DB_TBLName"; $result = mysql_query($query) or die('Error querying database.'); $file_ending = "xls"; header("Content-Type: application/octet-stream; charset=ISO-8859-13"); header("Content-Disposition: attachment; filename=$filename.xls"); header("Pragma: no-cache"); header("Expires: 0"); /******* Formatting Excel *******/ $sep = "\t"; //--1. start of printing column names as names of MySQL fields for ($i = 0; $i < mysql_num_fields($result); $i++) { $str = mysql_field_name($result,$i) . "\t"; $out = mb_convert_encoding($str, "ISO-8859-13", "UTF-8"); //$out=mb_detect_encoding($str); echo $out; } print("\n"); //--2. start while loop to get data while($row = mysql_fetch_row($result)) { $schema_insert = ""; for($j = 0; $j < mysql_num_fields($result);$j++) { if(!isset($row[$j])) $schema_insert .= "NULL".$sep; elseif ($row[$j] != "") { $word = mb_convert_encoding($row[$j], "ISO-8859-13", "ASCII"); //$word = mb_detect_encoding($row[$j]); $schema_insert .= $word.$sep; // $schema_insert .= "$row[$j]".$sep; } else $schema_insert .= "".$sep; } $schema_insert = str_replace($sep."$", "", $schema_insert); $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert); $schema_insert .= "\t"; // print(trim($schema_insert)); $schema_insert = trim($schema_insert); $out1 = mb_convert_encoding($schema_insert, "ISO-8859-13", "ASCII"); // print(trim($out1)); echo $out1; print ("\n"); } ?> The thing is that only the first part (see the code //--1.) works properly. That's because strings come from the code. BUT there are some problems with the second part (see code //--2.). Still doesn't work. Notice there is a commented line under elseif sentence '$word = mb_detect_encoding($row[$j]);' which can output what type of characters are. When I open excel file it says that all fields (rows) are ASCII format. So that's why I put everywhere (in the second part of the code only) the conversion from ASCII to ISO function. Unfortunately, this doesn't work... WHY?!
  4. I'm sorry guys.. This doesn't work. I'm totally sure that collation is OK, because I sorted out the problem by myself with correct UTF8 characters in Database two days ago. Check this out. So I'M SURE : )) Actually, I have no ideas how to fix this because this is the first time when I'm up against charsets settings so I'm still asking any suggestions : )
  5. Hi. I'm trying to export the content of MySQL table to Excel file. Exportation is executed with php code below: <?php $DB_TBLName = "reg_form"; $filename = "excelfile"; $dbc = mysql_connect('localhost', 'user', 'password') or die('Error connecting to MySQL server.'); $db_name = mysql_select_db('database', $dbc); $query = "SELECT first_name AS 'Pavardė', age AS 'Amžius', etc. etc. etc. FROM $DB_TBLName"; $result = mysql_query($query) or die('Error querying database.'); $file_ending = "xls"; header("Content-Type: application/octet-stream; charset=ISO-8859-13"); header("Content-Disposition: attachment; filename=$filename.xls"); header("Pragma: no-cache"); header("Expires: 0"); /******* Formatting for Excel *******/ $sep = "\t"; for ($i = 0; $i < mysql_num_fields($result); $i++) { echo mysql_field_name($result,$i) . "\t"; } print("\n"); while($row = mysql_fetch_row($result)) { $schema_insert = ""; for($j=0; $j<mysql_num_fields($result);$j++) { if(!isset($row[$j])) $schema_insert .= "NULL".$sep; elseif ($row[$j] != "") $schema_insert .= "$row[$j]".$sep; else $schema_insert .= "".$sep; } $schema_insert = str_replace($sep."$", "", $schema_insert); $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert); $schema_insert .= "\t"; print(trim($schema_insert)); print "\n"; } ?> But the problem is that some language specific characters are not recognized in that excel file. I know that Unicode for Microsoft (Excel) means a little bit different (like everything as usual and everywhere). Then I did some research and I finaly I tried this trick: $str = "ąčęėįšųūž"; $out = mb_convert_encoding($str, "ISO-8859-13", "UTF-8"); header('Content-type: application/octet-stream'); header("Content-Disposition: attachment; filename=excelfile.csv"); header("Pragma: no-cache"); header("Expires: 0"); echo $out; This works perfect. But as we can see mb_convert_encoding function works only for strings. But I need to convert all values from my table's columns and fields (see the first code paste above). The Q is how can I convert all values from my table from UTF8 to ISO-8859-13?
  6. thanks everybody for trying to help me : ) I'm still waiting for detailed explanation : ) Cheers
  7. HOLLY S**T!! FINALLY! : )))))))) The problem was that I was using mysqli_ queries. Now I tried to change to mysql_ (notice the change!) queries and it worked!! Two weeks of haaaaard working and researches... Phew! Now who can explain me properly the reasons of this phenomena? : ))
  8. Jazzman1, NOW I reinstalled (freshly) wordpress, created database using CREATE DATABASE db_name CHARACTER SET utf8 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT COLLATE utf8_general_ci ; Then, I created table using this: CREATE TABLE reg_form( `id` int(11) NOT NULL AUTO_INCREMENT, `first_name` char(50) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; Then I tried to fill the form field. Those strange hieroglyphic were saved. Then I tried your suggested method - to pass value straight from the code. STILL the same shit! : /
  9. But what's the point of this? On the other hand, I use the same and the only one database which contains: WP tables and reg_form table.
  10. I have well known but quite difficult to sort out problem here. And yes I was searching on forum but those threads are old enough so I decided to create new post. So I built a website using WP and included html FORM in one page. When user fills the form (in his/her language) the values of the fields' go into MySQL database table reg_form. Everything works, the values are saved, BUT some characters (specific in that language) are not recognized. I tried a lot of different methods to solve this, but nothing can help. The strangest thing is that if you look at WordPress tables you can find those specific characters are recognizable but not in reg_form table which I created. I was trying to solve this problem and finally I decided to approach in somehow ridiculous way. I created NEW database, new tables, installed new wordpress, created new form etc. That‘s what I was doing: I used this suggestion first: http://tympanus.net/codrops/2009/08/31/solving-php-mysql-utf-8-issues/ Yes, my files are saved using UTF8 encoding (without BOM). Yes, meta tags are ok. Yes, the FORM uses accept-charset='UTF-8'. Yes, all tables in database use UTF8. Yes, server, database and tables collation is the same “utf8_general_ci”. Then I tried to insert in my code this: $conn = mysql_connect($server, $username, $password); mysql_set_charset("UTF8", $conn); Then I tried this suggestion link here: http://akrabat.com/php/utf8-php-and-mysql/ Then I tried to set Apache's AddDefaultCharset in .htaccess file using this link here: http://httpd.apache.org/docs/2.0/mod/core.html#AddDefaultCharset BUT… still the problem remains. I can’t see those specific characters properly – only weird hieroglyphic.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.