PHP MySQL utf-8 Euro symbol shown as questionmark on a diamond - php

So after a whole day of googling and debugging I end up here.
MySQL
set to the following encoding:
db: utf8_general_ci
table: utf8_general_ci
column: utf8_general_ci, TEXT
I put in some euro symbols and some other weird characters
acentuação €€€€€
PHP (codeigniter)
config
$config['charset'] = 'UTF-8';
dsn
char_set=utf8,dbcollat=utf8_general_ci
I made some queries to compare
model
$query = $this->db->query("SET NAMES latin1");
$query = $this->db->query("SELECT shortdesc,HEX(shortdesc) FROM `contracttypes` WHERE id = 4");
$ret['latin1'] = $query->row();
$query = $this->db->query("SET NAMES utf8");
$query = $this->db->query("SELECT shortdesc,HEX(shortdesc) FROM `contracttypes` WHERE id = 4");
$ret['utf8'] = $query->row();
return $ret;;
controller
public function utfhell() {
var_dump($this->campagne_model->utfhell());
}
This outputs
array (size=2)
'latin1' =>
object(stdClass)[34]
public 'shortdesc' => string 'acentua��o �����' (length=16)
public 'HEX(shortdesc)' => string '6163656E747561C3A7C3A36F20E282ACE282ACE282ACE282ACE282AC' (length=56)
'utf8' =>
object(stdClass)[33]
public 'shortdesc' => string 'acentuação €€€€€' (length=28)
public 'HEX(shortdesc)' => string '6163656E747561C3A7C3A36F20E282ACE282ACE282ACE282ACE282AC' (length=56)
So far so good, on to a
view
<?php header('Content-Type: text/html; charset="utf-8"', true); ?>
<!doctype html>
<html>
<head>
<title>UTFhell</title>
<link rel="stylesheet" href="../assets/css/style.css"/>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
...
<?php
echo 'Original : ', $campagne_info->contractName->shortdesc."<br />";
echo 'UTF8 Encode : ', utf8_encode($campagne_info->contractName->shortdesc)."<br />";
echo 'UTF8 Decode : ', utf8_decode($campagne_info->contractName->shortdesc)."<br />";
echo 'TRANSLIT : ', iconv("ISO-8859-1", "UTF-8//TRANSLIT", $campagne_info->contractName->shortdesc)."<br />";
echo 'IGNORE TRANSLIT : ', iconv("ISO-8859-1", "UTF-8//IGNORE//TRANSLIT", $campagne_info->contractName->shortdesc)."<br />";
echo 'IGNORE : ', iconv("ISO-8859-1", "UTF-8//IGNORE", $campagne_info->contractName->shortdesc)."<br />";
echo 'Plain: ', iconv("ISO-8859-1", "UTF-8", $campagne_info->contractName->shortdesc)."<br />";
echo '€€€€€€€€€€<br>';
?>
None of these now show me a normal euro symbol except the final echo statement, they all give me questionmark diamonds for the eurosymbols

The HEX is the utf8 encoding for that string. So the data is in the table 'correctly'.
The black diamond (�) is the browser's way of saying wtf. It comes from having latin1 characters, but telling the browser
to display utf8 characters.
You could tell the browser to display "Western", that is avoiding the underlying problems.
Remember, the goal is to really use utf8.
Sometimes this occurs together with Question Marks, in which case you must start over.
The cause (probably):
The bytes you had were encoded latin1. You acquired them from somewhere -- file dump online input, etc.
The connection parameters said latin1.
The column/table is declared to be CHARACTER SET said utf8, so during INSERT, they were correctly converted.
When SELECTing, the seting in step 2 was again latin1, so they were converted back to latin1.
When displaying text in a web page, the page's header said that the bytes were utf8.
Solution, Plan A: (Sloppy, but probably workable)
Change #5 so say the appropriate equivalent of latin1.
Solution, Plan B:
Fix the source to be utf8-encoded
query("SET NAMES utf8") (unless there is a way to set it at connect time)
Leave the table/column at CHARACTER SET utf8
Step 2 cover this.
Leave <meta ... UTF-*>.

Related

Laravel: Unable to JSON encode payload. Error code: 5

I'm working on Laravel (v5.7) app that converts uploaded CSV (with contacts) into array that is then passed as argument when job class is being dispatched.
Here is the example of CSV file (format that is supported):
123456,Richard,Smith
654321,John,Doe
Uploaded (CSV) file is handled like this:
$file_path = $request->file_name->store('contacts');
$file = storage_path('app/' . $file_path);
$contactsIterator = $this->getContacts($file);
$contacts = iterator_to_array($contactsIterator); // Array of contacts from uploaded CSV file
protected function getContacts($file)
{
$f = fopen($file, 'r');
while ($line = fgets($f))
{
$row = explode(",", $line);
yield [
'phone' => !empty($row[0]) ? trim($row[0]) : '',
'firstname' => !empty($row[1]) ? trim($row[1]) : '',
'lastname' => !empty($row[2]) ? trim($row[2]) : '',
];
}
}
Finally, $contacts array is passed to a job that is dispatched:
ImportContacts::dispatch($contacts);
This job class looks like this:
public function __construct($contacts)
{
Log::info('ImportContacts#__construct START');
$this->contacts = $contacts;
Log::info('ImportContacts#__construct END');
}
public function handle()
{
Log::info('ImportContacts#handle');
}
... and everything worked fine (no errors) until I've tried with this CSV:
123456,Richardÿ,Smith
654321,John,Doe
Please notice ÿ. So, when I try with this CSV - I get this error exception:
/code_smsto/vendor/laravel/framework/src/Illuminate/Queue/Queue.php | 91 | Unable to JSON encode payload. Error code: 5
... and my log file looks like this:
error local 2019-11-11 17:17:18 /code_smsto/vendor/laravel/framework/src/Illuminate/Queue/Queue.php | 91 | Unable to JSON encode payload. Error code: 5
info local 2019-11-11 17:17:18 ImportContacts#__construct END
info local 2019-11-11 17:17:18 ImportContacts#__construct START
As you can see - handle method was never executed. If I remove ÿ - no errors and handle is executed.
I've tried to solve this, but without success:
Apply utf8_encode:
protected function getContacts($file, $listId)
{
$f = fopen($file, 'r');
while ($line = fgets($f))
{
$row = explode(",", $line);
yield [
'phone' => !empty($row[0]) ? utf8_encode($row[0]) : '',
'firstname' => !empty($row[1]) ? utf8_encode($row[1]) : '',
'lastname' => !empty($row[2]) ? utf8_encode($row[2]) : '',
];
}
}
... and it works (no errors, no matter if there's that ÿ), but then Greek and Cyrillic letters are turned into question marks. For example, this: Εθνικής will become ???????.
I also tried with mb_convert_encoding($row[1], 'utf-8') - and it doesn't turn Greek or Cyrillic letter into question marks, but this ÿ character will become ?.
Move "handling" (converting to array) of uploaded CSV file into #handle method of a Job class worked, but then I was not able to store the data from that array into DB (MongoDB). Please see the update below.
DEBUGGING:
This is what I get from dd($contacts);:
So, it has that "b" where ÿ is. And, after some "googling" I found that this "b" means "binary string", that is, a non unicode string, on which functions operate at the byte level (What does the b in front of string literals do?).
What I understand is this: When dispatching Job class, Laravel tries to "JSON encode" it (passed arguments/data) but it fails because there are binary data (non-unicode strings).
Anyway, I was not able to find a solution (to be able to handle such CSV file with ÿ).
I am using:
Laravel 5.7
PHP 7.1.31-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Aug 7 2019 10:22:48) ( NTS )
Redis powered queues
UPDATE
When I move "handling" (converting to array) of uploaded CSV file into #handle method of a Job class - I don't get this error (Unable to JSON encode payload. Error code: 5), but when I try to store that problematic binary data with ÿ (b"Richardÿ") into MongoDB - it fails. The weird thing is that I don't get any error-exception message in log file, so I put all in try-catch like this:
try {
// Insert data into MongoDB
} catch (Exception $e) {
Log::info($e->getFile());
Log::info($e->getLine());
Log::info($e->getMessage());
}
... and this is the result:
Anyway, I believe that it failed because of b"Richardÿ", and I guess that the solution is in encoding string, but as I've mentioned - I was not able to find a solution that works:
utf8_encode works (no errors, no matter if there's that ÿ), but then Greek and Cyrillic letters are turned into question marks. For example, this: Εθνικής will become ???????
mb_convert_encoding($row[1], 'utf-8') - it doesn't turn Greek or Cyrillic letter into question marks, but this ÿ character will become ?.
iconv('windows-1252', 'UTF-8', $row[1]) - works (no errors, no matter if there's that ÿ), but when there are Greek or Cyrillic letters - it fails (I get this error exception: iconv(): Detected an illegal character in input string)
You have several ways to deal with it but I'd recommend the following two. In both cases, the idea is that you store a UTF-8 string.
A simpler approach, figure out what encoding it is out of the (your) predefined list and convert it to UTF8.
$encoding = mb_detect_encoding($content, 'UTF-8, ISO-8859-1, WINDOWS-1252, WINDOWS-1251', true);
if ($encoding != 'UTF-8') {
$string = iconv($encoding, 'UTF-8//IGNORE', $row[1]);
}
The second approach is to use a third party library outlined in this answer

String with a "b" prefix on records with accent

When I dump the property of my model and it has an accent it returns with this "b" prefix
dump($venda_item->produto->nomeproduto); // b"teste téste"
My database is setted to utf8 and utf8_general_ci collation
This causes me the following error Malformed UTF-8 characters, possibly incorrectly encoded when I'm returning the response in json, at this line
$json_response = Response::json($response, $this->getStatusCode(), $headers);
Update
I discovered that if I die and dump the record on the web route it shows normal teste téste
Route::get('/', function () {
dd(App\Vendasitem::where('codigovi', 112685)->first()->produto->nomeproduto);
}
otherwise if I do the same in the controller or request and other files that I tryied it keeps returning me with the "b" prefix
Update 2
If I save my record like this PROMO - VIRICAPS (GUARANá + POLIVIT) 60 CáPS - CAIXA 18 UND and dump($venda_item->produto->nomeproduto); it returns me the right result with the accents.
All my database, including the column is set up to utf8mb4 and utf8mb4_unicode_ci
If you already confirmed the encoding on your database. Have a look on config/database.php, on charset and collation proprieties.
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci'
If the issue is on the "print" then you might use the utf8_encode function.
{{utf8_encode($yourVar)}}
I had this problem when importing data from a different database. Solved with this method, maybe it works for you to.
public function fixEncoding($str) {
return mb_check_encoding($str, 'UTF-8')
? html_entity_decode($str)
: utf8_encode(html_entity_decode($str));
}
So, it looks like your best bet is to write a accessor for the object using iconv:
public function getNomeprodutoAttribute($value) {
return iconv("utf-8", "utf-8//ignore", $value);
}
Unless you want to recode the whole database, which probably isn't an option.
The value passed in will the value out of the database (which is the unfortunate binary data). Then you are telling it the input is utf (which it is), and that the output is utf8 (which we want) but to ignore chars that aren't supported in utf-8. //ignore may work in some versions of the library, so you'd just have to do the following, and hope for the best:
public function getNomeprodutoAttribute($value) {
return iconv("utf-8", "utf-8", $value);
}
Use this function
public function utf8ize($value) {
if (is_array($value)) {
foreach ($value as $k => $v) {
$value[$k] = utf8ize($v);
}
} else if (is_string ($value)) {
return utf8_encode($value);
}
return $value;
}

Unable to retrieve UTF-8 accented characters from Access via PDO_ODBC

I am trying to get an Access DB converted into MySQL. Everything works perfectly, expect for one big monkey wrench... If the access db has any non standard characters, it wont work. My query will tell me:
Incorrect string value: '\xE9d'
If I directly echo out the rows text that has the 'invalid' character I get a question mark in a black square in my browser (so é would turn into that invalid symbal on echo).
NOTE: That same from will accept, save and display the "é" fine in a textbox that is used to title this db upload. Also if I 'save as' the page and re-open it up the 'é' is displayed correctly....
Here is how I connect:
$conn = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=$fileLocation;SystemDB=$securefilePath;Uid=developer;Pwd=pass;charset=utf;");
I have tried numerous things, including:
$conn -> exec("set names utf8");
When I try a 'CurrentDb.CollatingOrder' in access it tells me 1033 apparently that is dbSortGeneral for "English, German, French, and Portuguese collating order".
What is wrong? It is almost like the PDO is sending me a collation my browser and PHP does not fully understand.
The Problem
When using native PHP ODBC features (PDO_ODBC or the older odbc_ functions) and the Access ODBC driver, text is not UTF-8 encoded, even though it is stored in the Access database as Unicode characters. So, for a sample table named "Teams"
Team
-----------------------
Boston Bruins
Canadiens de Montréal
Федерация хоккея России
the code
<?php
header('Content-Type: text/html; charset=utf-8');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Access character test</title>
</head>
<body>
<?php
$connStr =
'odbc:' .
'Driver={Microsoft Access Driver (*.mdb)};' .
'Dbq=C:\\Users\\Public\\__SO\\28311687.mdb;' .
'Uid=Admin;';
$db = new PDO($connStr);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT Team FROM Teams";
foreach ($db->query($sql) as $row) {
$s = $row["Team"];
echo $s . "<br/>\n";
}
?>
</body>
</html>
displays this in the browser
Boston Bruins
Canadiens de Montr�al
????????? ?????? ??????
The Easy but Incomplete Fixes
The text returned by Access ODBC actually matches the Windows-1252 character encoding for the characters in that character set, so simply changing the line
$s = $row["Team"];
to
$s = utf8_encode($row["Team"]);
will allow the second entry to be displayed correctly
Boston Bruins
Canadiens de Montréal
????????? ?????? ??????
but the utf8_encode() function converts from ISO-8859-1, not Windows-1252, so some characters (notably the Euro symbol '€') will disappear. A better solution would be to use
$s = mb_convert_encoding($row["Team"], "UTF-8", "Windows-1252");
but that still wouldn't solve the problem with the third entry in our sample table.
The Complete Fix
For full UTF-8 support we need to use COM with ADODB Connection and Recordset objects like so
<?php
header('Content-Type: text/html; charset=utf-8');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Access character test</title>
</head>
<body>
<?php
$connStr =
'Driver={Microsoft Access Driver (*.mdb)};' .
'Dbq=C:\\Users\\Public\\__SO\\28311687.mdb';
$con = new COM("ADODB.Connection", NULL, CP_UTF8); // specify UTF-8 code page
$con->Open($connStr);
$rst = new COM("ADODB.Recordset");
$sql = "SELECT Team FROM Teams";
$rst->Open($sql, $con, 3, 3); // adOpenStatic, adLockOptimistic
while (!$rst->EOF) {
$s = $rst->Fields("Team");
echo $s . "<br/>\n";
$rst->MoveNext;
}
$rst->Close();
$con->Close();
?>
</body>
</html>
A bit more easily to manipulate the data. (Matrix array).
function consulta($sql) {
$db_path = $_SERVER["DOCUMENT_ROOT"] . '/database/Registros.accdb';
$conn = new COM('ADODB.Connection', NULL, CP_UTF8) or exit('Falha ao iniciar o ADO (objeto COM).');
$conn->Open("Persist Security Info=False;Provider=Microsoft.ACE.OLEDB.12.0;Jet OLEDB:Database Password=ifpb#10510211298;Data Source=$db_path");
$rs = $conn->Execute($sql);
$numRegistos = $rs->Fields->Count;
$index = 0;
while (!$rs->EOF){
for ($n = 0; $n < $numRegistos; $n++) {
if(is_null($rs->Fields[$n]->Value)) continue;
$resultados[$index][$rs->Fields[$n]->Name] = $rs->Fields[$n]->Value;
echo '.';
}
echo '<br>';
$index = $index + 1;
$rs->MoveNext();
}
$conn->Close();
return $resultados;
}
$dados = consulta("select * from campus");
var_dump($dados);
Found the following solution. True, I did not have the opportunity to test it on php. But I suppose it should work out.
In order for native PHP ODBC features (PDO_ODBC or the older odbc_ functions) and the Access ODBC driver to be able to correctly subtract texts in Unicode encoding, that stored in the Access database as Unicode character, it is need enables "Beta: Use Unicode UTF-8 for worldwide language support" in Region Settiongs of Windows Operetion System.
After I did this at me, many programs using the standard ODBC driver MC Access, began to display correct texts in Unicode encoding.
All Settings -> Time & Language -> Language -> "Administrative Language Settings"

PHP output JSON Web Service charset UTF-8 error

I am hosting a web service in JSON output by PHP.
I have Hebrew data set in DB and I am posting this as an output to Web service.
When I post the data initially it output the result as follows:
JSON:
{
"tasklist": [
{
"customerID": "9936",
"name": "טר ×רמה ×™×–×•× ×•×‘×™× ×•×™ בע"מ",
"cargo":"×ברר",
"destination":"מכר",
"quantity":"1.000000",
"startdate":"03/01/201300: 00: 00"
}
]
}
But this "×ברר" can be readable by Android/Iphone parser and convert it to original Hebrew. But i faced Error in "name": "טר ×רמה ×™×–×•× ×•×‘×™× ×•×™ בע"מ",. where " is in between the string so the JSON is not valid and shows error!
To Over come this issue I used UTF-8 to convert "×ברר" this to Hebrew "נברר". But in this case too the problem remains same:
PHP:
header('Content-type: text/html; charset=UTF-8');
JSON:
{
"tasklist": [
{
"customerID": "9936",
"name": "טר ארמה יזום ובינוי בע"מ",
"cargo":"נברר",
"destination":"מכר",
"quantity":"1.000000",
"startdate":"03/01/201300: 00: 00"
}
]
}
But still the problem remains:
Also in some case I am getting this � because of using UTF-8
"name":"מחצבות כפר גלעדי-חומרי מ�"
How can I overcome this issue?
Is there any other specific encode I need to use?
Note: The data cannot be changes in Database The solution should be while output to JSON.
How the data stored in DB is shown below:
name
מחצבות כפר גלעדי-חומרי מ×
My PHP Script which output JSON:
<?php
//My DB connection and Query comes here
$jsontext = '{"tasklist":[';
while($row = mysql_fetch_array($queryExe)){
$jsontext .= '{"customerID":"'.$row['AUTO_ID'].'",';
$jsontext .='"name":"'.$row['Customer_Name'].'",';
$jsontext .='"cargo":"'.$row['Type_of_Cargo'].'",';
$jsontext .='"destination":"'.$row['Destination'].'",';
$jsontext .='"quantity":"'.$row['Quantity'].'",';
$jsontext .='"startdate":"'.$row['startdate'].'"},';
}
$jsontext = substr_replace($jsontext, '', -1); // to get rid of extra comma
$jsontext .= "]}";
header('Content-type: text/html; charset=UTF-8');
//Output the final JSON
echo $jsontext;
?>
Thank you for your help in advance!
Was the question clear? to understand my issue.
If your db-field is utf8 you should fist do:
mysql_query("SET NAMES 'utf8'");
You should always do the 'SET NAMES...' before inserting your data, too.
Be sure that you really stored utf8 encoded strings!
then do your query:
mysql_query($your_query);
$array = array("tasklist"=>array());
while($row = mysql_fetch_array($queryExe)){
$a = array();
$a["customerID"] = $row['AUTO_ID'];
$a["name"] = $row['Customer_Name'];
$a["cargo"] = $row['Type_of_Cargo'];
$a["destination"] = $row['Destination'];
$a["quantity"] = $row['Quantity'];
$a["startdate"] = $row['startdate'];
$array["tasklist"][] = $a;
}
header("Content-type: application/json; charset=utf-8");
echo json_encode($array);
exit();
i've made the experience that these is not enough when the servers default charset is for example iso. In that case i need to do the following in my .htaccess:
AddDefaultCharset utf-8
You should change your code to use json_encode. You need to pass it properly utf8 encoded data.
If you are using MySQL you can try running the following before your query to get your data.
SET NAMES 'utf8';
You can also look into using utf8_encode.
From http://www.php.net/manual/en/function.json-encode.php#100565
That said, quotes " will produce invalid JSON, but this is only an issue if you're using json_encode() and just expect PHP to magically escape your quotes. You need to do the escaping yourself.
May be you can replace " with \" , i guess it will solve the issue.
Source : PHP JSON String, escape Double Quotes for JS output

iconv encoding conversion with iconv windows-1256

When encoding the language "UTF-8" to "windows-1256" files I notice letters to lose I do not know why
Example of the text
<?php
$JSON = file_get_contents("http://gdata.youtube.com/feeds/api/videos?q=sUAvgNwQsaM&alt=json");
$JSON_Data = json_decode($JSON);
$title = $JSON_Data->{'feed'}->{'entry'}[0]->{'title'}->{'$t'};
$title= iconv("UTF-8","windows-1256","$title");
echo $youtube;
?>
If it has been deleted
iconv("UTF-8","windows-1256","$title");
Full text will appear and I did not encode windows-1256
How to solve this problem
A text input to databases windows-1256 encoding
Greetings
Try this: (not my code)
$f[]="\xc2\xac"; $t[]="\x80";
$f[]="\xd9\xbe"; $t[]="\x81";
$f[]="\xc0\x9a"; $t[]="\x82";
$f[]="\xc6\x92"; $t[]="\x83";
$f[]="\xc0\x9e"; $t[]="\x84";
$f[]="\xc0\xa6"; $t[]="\x85";
$f[]="\xc0\xa0"; $t[]="\x86";
$f[]="\xc0\xa1"; $t[]="\x87";
$f[]="\xcb\x86"; $t[]="\x88";
$f[]="\xc0\xb0"; $t[]="\x89";
$f[]="\xd9\xb9"; $t[]="\x8a";
$f[]="\xc0\xb9"; $t[]="\x8b";
$f[]="\xc5\x92"; $t[]="\x8c";
$f[]="\xda\x86"; $t[]="\x8d";
$f[]="\xda\x98"; $t[]="\x8e";
$f[]="\xda\x88"; $t[]="\x8f";
$f[]="\xda\xaf"; $t[]="\x90";
$f[]="\xc0\x98"; $t[]="\x91";
$f[]="\xc0\x99"; $t[]="\x92";
$f[]="\xc0\x9c"; $t[]="\x93";
$f[]="\xc0\x9d"; $t[]="\x94";
$f[]="\xc0\xa2"; $t[]="\x95";
$f[]="\xc0\x93"; $t[]="\x96";
$f[]="\xc0\x94"; $t[]="\x97";
$f[]="\xda\xa9"; $t[]="\x98";
$f[]="\xc4\xa2"; $t[]="\x99";
$f[]="\xda\x91"; $t[]="\x9a";
$f[]="\xc0\xba"; $t[]="\x9b";
$f[]="\xc5\x93"; $t[]="\x9c";
$f[]="\xc0\x8c"; $t[]="\x9d";
$f[]="\xc0\x8d"; $t[]="\x9e";
$f[]="\xda\xba"; $t[]="\x9f";
$f[]="\xd8\x8c"; $t[]="\xa1";
$f[]="\xda\xbe"; $t[]="\xaa";
$f[]="\xd8\x9b"; $t[]="\xba";
$f[]="\xd8\x9f"; $t[]="\xbf";
$f[]="\xdb\x81"; $t[]="\xc0";
$f[]="\xd8\xa1"; $t[]="\xc1";
$f[]="\xd8\xa2"; $t[]="\xc2";
$f[]="\xd8\xa3"; $t[]="\xc3";
$f[]="\xd8\xa4"; $t[]="\xc4";
$f[]="\xd8\xa5"; $t[]="\xc5";
$f[]="\xd8\xa6"; $t[]="\xc6";
$f[]="\xd8\xa7"; $t[]="\xc7";
$f[]="\xd8\xa8"; $t[]="\xc8";
$f[]="\xd8\xa9"; $t[]="\xc9";
$f[]="\xd8\xaa"; $t[]="\xca";
$f[]="\xd8\xab"; $t[]="\xcb";
$f[]="\xd8\xac"; $t[]="\xcc";
$f[]="\xd8\xad"; $t[]="\xcd";
$f[]="\xd8\xae"; $t[]="\xce";
$f[]="\xd8\xaf"; $t[]="\xcf";
$f[]="\xd8\xb0"; $t[]="\xd0";
$f[]="\xd8\xb1"; $t[]="\xd1";
$f[]="\xd8\xb2"; $t[]="\xd2";
$f[]="\xd8\xb3"; $t[]="\xd3";
$f[]="\xd8\xb4"; $t[]="\xd4";
$f[]="\xd8\xb5"; $t[]="\xd5";
$f[]="\xd8\xb6"; $t[]="\xd6";
$f[]="\xd8\xb7"; $t[]="\xd8";
$f[]="\xd8\xb8"; $t[]="\xd9";
$f[]="\xd8\xb9"; $t[]="\xda";
$f[]="\xd8\xba"; $t[]="\xdb";
$f[]="\xd9\x80"; $t[]="\xdc";
$f[]="\xd9\x81"; $t[]="\xdd";
$f[]="\xd9\x82"; $t[]="\xde";
$f[]="\xd9\x83"; $t[]="\xdf";
$f[]="\xd9\x84"; $t[]="\xe1";
$f[]="\xd9\x85"; $t[]="\xe3";
$f[]="\xd9\x86"; $t[]="\xe4";
$f[]="\xd9\x87"; $t[]="\xe5";
$f[]="\xd9\x88"; $t[]="\xe6";
$f[]="\xd9\x89"; $t[]="\xec";
$f[]="\xd9\x8a"; $t[]="\xed";
$f[]="\xd9\x8b"; $t[]="\xf0";
$f[]="\xd9\x8c"; $t[]="\xf1";
$f[]="\xd9\x8d"; $t[]="\xf2";
$f[]="\xd9\x8e"; $t[]="\xf3";
$f[]="\xd9\x8f"; $t[]="\xf5";
$f[]="\xd9\x90"; $t[]="\xf6";
$f[]="\xd9\x91"; $t[]="\xf8";
$f[]="\xd9\x92"; $t[]="\xfa";
$f[]="\xc0\x8e"; $t[]="\xfd";
$f[]="\xc0\x8f"; $t[]="\xfe";
$f[]="\xdb\x92"; $t[]="\xff";
function utf8_to_win($str) {
global $f, $t;
return str_replace($f, $t, $str);
}

Categories