0

I have JSON API server its working fine.

What my server does is, It takes the requests from clients in text format, example "Movie Name". And look for the requested string (Movie Name) on the other server, the other server will reply back the details of the Movie, such as released date, Language and rating etc... and my server will return back the details to client, all is working fine.

i keep the requested_logs(MovieNames) means if the query succeeded with result from other server then it will log it in a file with Movie Name, also i keep the logs of not_found_logs means if the other server reply NULL my server will keep the logs as NOT_FOUND and the Movie Name.

i check the logs every now and then and i found some strange characters in both files Requested_logs and Not_Found_Logs

My clients requested to my server this strings

1. Aniołki Charliego
2. Książę Persji: Piaski czasu
3. Złap mnie, jeśli potrafisz
4. Bogowie i potwory

These are very strange characters for me to understand but what shock me that, this Movie Names get logged in my Requested_log file means the other server also understand the request and reply the result !

what i did i copy the text and tried the google translate and it got translated to these. It shows Detected Languages -> Polish

1. Aniołki Charliego => Charlie's Angels
2. Książę Persji: Piaski czasu => Prince of Persia: The sands of time
3. Złap mnie, jeśli potrafisz => Catch me if you can
4. Bogowie i potwory => Gods and monsters

I don't understand how polish language can have characters like "Książę" and how the other server and the google-translate can understand this characters ?

Can somebody explain this behavior and also if possible please suggest me to save the exact same translated text to my logs file instead the RAW strings for PHP

Thanks

  • Encoding? Andi,Ascii,Codepage,Unicode ... – bummi Apr 06 '19 at 09:25
  • You have an issue with character encoding. Question is in what component. If you are lucky then it is just the tool you use to visualize the contents of those files, so probably some text editor or similar. – arkascha Apr 06 '19 at 09:49
  • And another question: why do you use files for this? Why not a simple database which is _much_ faster? – arkascha Apr 06 '19 at 09:49
  • @arkascha I just started to learn programming, thanks for your suggestion on database, i will do it sure. I use the NOTEPAD++ to view the logs my next plan is to save the logs in SQL and fetch whenever needed but i don't know from where to start. As of now im just learning and monitoring (Debugging) the codes. – Mohammed Azeem Apr 06 '19 at 10:06
  • OK, notepad++ as a text editor means that you are using MS-Windows as operating system on your desktop. MS-Windows is well known for various issues, one of those actually is problems with character encoding depending on how it got installed and updated. I assume your web application operates on another system which most likely runs a Linux operating system? So you transfer files between systems? Or do you use some network access to those files for viewing them? – arkascha Apr 06 '19 at 10:16
  • All it takes, is one wrong charset setting in your application - *everything* needs to be the same charset! I have previously written [**an answer about UTF-8 encoding**](https://stackoverflow.com/a/31899827/4535200) that contains a little checklist, that will cover *most* of the charset issues in a PHP/MySQL application. There's also a more in-depth topic, [**UTF-8 All the Way Through**](https://stackoverflow.com/q/279170/4535200). Most likely, you'll find a solution in either one or both of these topics. – Qirel Apr 06 '19 at 10:25
  • @arkascha Yes im using the windows 7 64bits and my server is installed on UNiX PHP Im accessing the log file from server in my windows by using the filezilla FTP – Mohammed Azeem Apr 07 '19 at 11:12
  • @Qirel since my server can communicate with my client and other server means it decode the characters well, I will try to save the logs to mysql instead txt file and update the result – Mohammed Azeem Apr 07 '19 at 11:12
  • Before making experiments and trying things out blindly (mysql won't change a thing depending on what the actual problem is) it would make more sense to first find the thing that actually causes the issue. That is not done by guessing or by trying around. That is done by debugging. For that you need to, as a first step, take a look into those files and decide what they actually contain. You need a `hexeditor` for that which allows to see the actual numbers coding the characters. That allows to see what is _really_ stored inside those files, not just what your notepad application interprets. – arkascha Apr 07 '19 at 13:46

0 Answers0