SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 20/11/2019, 01:18 PM   #1
Jacoves
Little Clucker
 
Join Date: Jun 2016
Posts: 7
Reputation: 0
Default HTTP and utf-8 encoding

(Using ****** translate...)


I did a little test using the HTTP library and a web page that displayed only text written olŠ. In the test I wanted to get the content of this page on the internet (in this case only the text olŠ) through a command in the game, where the player typed for example: /test and would be displayed to him a message with the page content. The problem is that instead of being displayed olŠ to the player is being displayed ol√°. The code looks like this:
Code:
CMD:test(playerid, params[]){
      HTTP(playerid, HTTP_GET, "mysite.com/ola.php", "", "Response");
      return 1;
}

forward Response(index, response_code, data[]);
public Response(index, response_code, data[])
{
    if(response_code == 200)
    { 
        SendClientMessage(index, 0xFFFFFFFF, data);
    }
}

in my page

PHP Code:
<?php 
     
echo 'olŠ';
?>
I was wondering if this is normal and if I would need a function to encode what is received or if it is caused by something else.

Last edited by Jacoves; 20/11/2019 at 06:32 PM.
Jacoves is offline   Reply With Quote
Old 20/11/2019, 07:17 PM   #2
Kaliber
High-roller
 
Kaliber's Avatar
 
Join Date: Jun 2012
Location: Localhost
Posts: 1,068
Reputation: 149
Default Re: HTTP and utf-8 encoding

Try:

PHP Code:
<?php 
    header
('Content-Type: text/html; charset=utf-8');
    echo 
'olŠ';
?>
__________________
Kaliber is offline   Reply With Quote
Old 21/11/2019, 08:17 PM   #3
Jacoves
Little Clucker
 
Join Date: Jun 2016
Posts: 7
Reputation: 0
Default Re: HTTP and utf-8 encoding

Thanks for the reply Kaliber!

I tried using charset but it didn't work either ..

I also tried other things like changing the default windows font to Arial, doing some updates on my windows, downloading the samp server folder again and just adding this line of code in a clean gamemode but it didn't work.
Jacoves is offline   Reply With Quote
Old 22/11/2019, 01:22 AM   #4
KittyChloe
Little Clucker
 
KittyChloe's Avatar
 
Join Date: Oct 2019
Posts: 28
Reputation: 13
Default Re: HTTP and utf-8 encoding

you do realize that its the same as just doing
SendClientMessage(playerid, -1, "olŠ");
only difference is that you're wasting a ton of time doing this.
__________________
rawr
KittyChloe is offline   Reply With Quote
Old 22/11/2019, 01:31 AM   #5
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,473
Reputation: 1632
Default Re: HTTP and utf-8 encoding

Chloe: You do realize it.is a test to check if everything.is OK? ;-) CMD:test. Atleast I ASSUME so.
And I do hope OP realizes that too. If not. Well...

@OP idk honestly. It is a long shot but you could try using chr() function to output the Š. Tho pretty sure it wont work since output will be the same. But no harm in trying.
__________________
Do not click on this URL -It is secret information
RIP Slayer 1981-2019 \m/
Kwarde is offline   Reply With Quote
Old 22/11/2019, 05:43 PM   #6
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,654
Reputation: 559
Default Re: HTTP and utf-8 encoding

You need to use Windows-1252 if you want the SAMP server to read it correctly. This also means switching the charset in the header AND editor, otherwise it will show incorrectly in browsers.

Additionally you can use iconv() if you want to convert between charsets without switching the charset in your editor (or if you can't):

Code:
<?php
header('Content-Type: text/html; charset=Windows-1252');
echo iconv('UTF-8', 'Windows-1252', 'olŠ');
?>
You can also create a second PHP file that takes the original UTF-8 PHP file and converts the whole thing to Windows 1252, to avoid using iconv for every line of text. This way the original will be in UTF-8 (for browsers) and the SAMP Server gets Windows-1252:

Code:
<?php
header('Content-Type: text/html; charset=Windows-1252');
echo iconv('UTF-8', 'Windows-1252', include("./ola.php"));
?>
But that shouldn't be neccessary.
NaS is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql encoding Sielly Scripting Help 6 03/08/2016 04:17 PM
Encoding problem? Patchwerk Scripting Help 0 09/05/2014 04:19 PM
[HTTP] Why is my HTTP/PHP script not working? Sinner Scripting Help 2 26/09/2013 05:24 PM
HTTP() callback won't fire, + server crash using HTTP() KoczkaHUN Bug Reports 6 14/12/2011 10:35 AM


All times are GMT. The time now is 02:00 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.