Flex datagrid unicode characters - php

So i was asked to build a flex application to store clients for a local business. However it needs to store the clients using Greek characters. My problem is that when importing a name in the datagrid in Greek it work Λεωνίδας When i try to put it in the database using phpmyadmin it seems to be ok but then it comes like ??????????? in the datagrid. My set is flex application connecting to mysql using php services. I have setted the encoding of the database to be utf8-general with no luck. Im not sure if this is a problem with flex or with the services. Any ideas?

This forum discussion presents ideas for how to use special characters in Flash/Flex including Greek characters. See Kostas Zotos' post for a potential solution with these building blocks:
Use utf-8 encoding.
Use an xml file with a CDATA block to list greek characters.
Use device fonts, not embedded fonts.

So after a bit of research in greek flex and php forums i found out a solution. in order to access any utf8 language from flex the only thing that needs to be done is to add
mysqli_query($this->connection, "set names utf8");
before any sql statements in the methods of the service files (getAllSomething). This will allow to write and retrieve utf8 charsets in any language without a problem.
i hope this will be helpful to other flex developers as well.

Related

How to deal with legacy app storing Arabian characters in latin1 database

I now work on a web-base PHP app to work with a MySQL Server database .
database is with Latin1 Character set and all Persian texts don't show properly .
database is used with a windows software Show and Save Persian texts good .
I don't want to change the charset because windows software work with that charset .
Question:
how can convert latin1 to utf8 to show and utf8 to latin1 for saving from my web-base PHP app , or using Persian/Arabic language on a latin1 charset database without problem ?
note:
one of my texts is احمد رحمانی when save from my windows-based software save as ÇÍãÏ ÑÍãÇäí and still show with احمد رحمانی in my old windows-based software
image : image of database , charsets,collation and windows-based software (full Size)
Edit: Your screenshot shows that the diagnosis below is probably correct.
What to do: Try using iconv() in your PHP web application. You would have to guess or find out what collation/codepage your Windows app uses.
Then something like this might work:
$string_decoded = iconv("windows-1256", "utf-8", $string);
You may need to experiment to get this working. Also, I think you need to force your database connection to use latin1 instead of UTF-8!
If you ask me, this is not a good basis for your web app. You would have to convert data into a broken format all the time. You may have to break compatibility with your application, or write an import tool.
The latin1 character set does not cover Persian characters. Proof at collation-charts.org
The only explanation I have why your Delphi program is able to store Arabic characters in a latin1 database is, it could be misusing the latin1 database to store data that isn't covered by latin1, e.g. Windows-1256 Arabic. So the program would store the raw bytes of each arabic character, while in fact these bytes are occupied by other, latin characters in the latin1 character set. But as long as was only the Delphi program storing and fetching the data, no one noticed.
If I'm correct in that - it's the only way I can see how what you describe could be happening - that works as long as only applications are involved that do this the same way, a way which is wrong really.
You should be able to confirm whether this is the case by looking at the data from a "neutral" database tool like phpMyAdmin or HeidiSQL. If you see garbage there instead of Arabic / Persian characters, I may be right.
As to what to do to make your PHP web app work with the same database as your Delphi app - I'm not really sure what to do to be honest. As far as I know, there is no way to force mySQL to use one encoding instead of the other. You would have to manually "re-encode" the data before fetching it into your web app. This is likely to be a painful process.
But first, try to find out what exactly is happening.

Supporting other languages

I have a web-based tool, that is mainly used in English. I just received a question if it will support Thai language. Since it is mostly text based, what modifications do I need to make to support other languages, like Thai specifically?
First, you need to make sure you are using UTF8 encoding from end to end. That means in code, output, database and database connection. For PHP you should set mb_internal_encoding and mb_http_output to UTF-8.
Your output headers should be set UTF8. For example:
Content-Type:text/html; charset=UTF-8
If you are using MySQL, make sure your tables are UTF-8, you can convert them with an ALTER TABLE. For safety, you should also set your db connection to UTF-8 by running SET NAMES UTF8 as the first query on every connection.
Once you have that, then you can support most languages (i.e. not Chinese). THEN you can remove all your text from your HTML and put it in some sort of lookup system. A common solution is the gettext support in PHP. Although you may want to come up with your own solution that can search and replace in bulk.
While it's not trivial to do all this, once it's done it's easy to support more languages. You just need to translate your text. Bing has a free/cheap translation service with good terms. Google used to, but changed their policies about a year ago. Google still have a translation service, but the terms did not work for my needs.
Your question is a big topic, but this information should point you in the right direction.

PHP Making Application Compatible With Other Language Characters

I have created a small contact form creator in PHP and everything works fine for me, but my friend in Denmark says the forms don't display danish characters properly and won't submit when Danish characters are used. I have never worked with internationalization and the PHP manual doesn't help me at all.
How can I make my PHP applications be compatible with other language characters. I work with PHP 5.3.x and my files are created with utf-8 without bom and everything in my pages and database are utf-8. Is there an article you can recommend that a beginner can understand?
Thank you!
1.Add meta charset on your page
2.Serve Content-Type:text/html; charset=utf-8 in header
3.Use set names for mysql, see SET NAMES utf8 in MySQL?
Seems you have everything that needs to be, but clearly there's some little thing probably one of the things that you think that is in place.
Whatever, as a last resort, you can use php's htmlspecialchars() function to encode all chars into html entities.

utf-8 encoding in HTML and utf8_unicode_ci char set & collation for MySQL - can I store & display any type of text in it now?

I want to dvp a small web app which would ideally be used worldwide. For the sake of the discussion, let's say it's a recipe sharing site - it's a good enough metaphor.
My app will allow users to enter or upload text in their native languages. My html header says that the site uses utf-8 encoding. I am now creating my MySQL db, and I suppose that I should select utf8_unicode_ci for the char set & collation.
Is that correct?
Is that all I need to do to be able to receive, store, and display safe user-generated-content in their chosen language? If not, what am I missing?
(I am aware of the safety concerns associated with displaying UGC, this is not what the question is about - here I am solely looking for advice to deal with safe content.)
It is all for you HTML and DB part, but you must ensure that the programming language is UTF-8 aware so it doesn't garble your stuff. If you use PHP just make sure that the functions you use are UTF-8 aware. If it isn't the manual usually mentions it.
As far as the html and the db i think this is all you need.
The only other part you may need to define that your inputs are UTF-8 encoded, is the part where you send/receive your data (assuming with a form and a post request for example).
You can check post #:1281123 in this forum, it helped a lot when i had some problems with encoding in a similar situation.

PHP search engine problem

Im using Sphider as a search engine for my website, its really easy to work with but im having some major issues with localized characters.
All of my html/php pages have the charset defined as UTF-8 and the search and result page from Sphider had charset=ISO-8859-1, when I first used the Sphider "spider" to crawl my website it made all of my localized characters into some codification I dont know:
"ç" become "ç" and so on with "ã", "á" etc
When I created the DB in MySql I made it a utf-8_general_ci also my defenitions for the DB are :
MySQL charset: UTF-8 Unicode (utf8)
MySQL connection collation: utf-8_unicode_ci
This is a real problem because the search wont work properly, if I search "diferença" for instance, in the url it will appear as "?query=diferença&search=1" which is correct but will produce no results in the "suggested search" it will appear as "diferen�a" in case its not visible, the "ç" has become a black square with a white question mark on it.
I believe the spider might have a different working charset but I dont seem able to understand were if it is to be the case. Also being developed towards English primarily I believe its not hard to understand that it has some hiccups along the way.
Does anyone has any experience with it or what should I try to do to solve this?
What really bugging me is not understanding why I get strange symbols in the DB.
Quickly browsing through some Sphider source code files revealed that the application works only with Latin1 charset. You should switch to some other search engine, like Lucene. You'll need to do a bit more search-related coding though. If you don't feel like doing it, and your site is public, just integrate Google search.
You should have EVERYTHING in utf-8.
The forms who edit any given page
The physical files
The outputted html files
The headers
The connection to the database
The table definition
Miss one and you will have problems (I'm talking from personal experience)
Modify the line 4 of file "header.html" in appropriate template directory to <meta http-equiv="content-type" content="text/html; charset=UTF-8">
Convert the appropriate php file in "languages" directory to UTF8.
If the above doesn't suffice, follow the answer by The Disintegrator as well.

Categories