php insert text file to mysql encoding -


i have import data .txt file mysql db.

when open txt notepad file written in dos/windows ansi (encode in ansi). when open akelpad info file encoded in 1253 (ansi-greek)

i import data below code

$myfile = "bill.txt"; $fh = fopen($myfile, 'r'); $thedata1 = fread($fh, filesize($myfile)); $thedata = str_replace("'","#",$thedata1); $thedata = iconv('cp1253','utf-8',$thedata); $data = (filesize($myfile))/156; fclose($fh); $line = 0;  mysql_query("truncate bill"); ($counter = 1; $counter <= $data; $counter++) {   $barcode[counter] = substr($thedata, ($line+0), 10);   $buildingcode[counter] = substr($thedata, ($line+10), 5);   $buildingaddress[counter] = substr($thedata, ($line+14), 40);   $flatname[counter] = substr($thedata, ($line+54), 50);   $flatdescription[counter] = substr($thedata, ($line+104), 8);   $entryseason[counter] = substr($thedata, ($line+112), 23);   $period[counter] = substr($thedata, ($line+135), 11);   $amountint = substr($thedata, ($line+146), 7);   $amountdec = substr($thedata, ($line+153), 2);   $amount[counter] = $amountint.'.'.$amountdec;    mysql_query("insert bill (id, code, address, name, description, entryseason, period, revenue)    values ('$barcode[counter]', '$buildingcode[counter]', '$buildingaddress[counter]', '$flatname[counter]', '$flatdescription[counter]', '$entryseason[counter]', '$period[counter]', '$amount[counter]')");    $line = $counter * 156; } 

when read above data code

$query = "select * bill order id asc";  $result = mysql_query($query) or die(mysql_error()); $i=0; while ($row=mysql_fetch_array($result)){ $i=$i+1; echo $i." - ".$row['id']. " - ". $row['code']. " - ". $row['address']. " - ". $row['name']. " - ". $row['description']. " - ". $row['entryseason']. " - ". $row['period']. " - ". $row['revenue'].'<br>'; 

i receive greek letters. when check db phpmyadmin greek entries chars ÃÅÙÑÃ.ÃÅÍÍÇÌÁÔÁ 39Á

if try insert entrys mysql sqlite letters these ÃÅÙÑÃ.ÃÅÍÍÇÌÁÔÁ 39Á

where wrong?

there several things wrong

1) sure using utf-8 database, table, column in database trying save data?

2) run mysql_query("set names utf8"); before run select/update database?

if doing both right, suggest debug in bigger detail.

3) try specify 1 character in txt file , try echo ord($str{xxx}) before , after iconv function , check if binary data utf-8 correctly encoded.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -