Thread Closed

#1
Any idea how to pass special characters form js to php to html
nothing I try will pass � correctly
send to php from js

js:
encodeURIComponent('�')//sent via ajax
to php:
echo urldecode($_GET);
to html:
Ã?¢ââ??¢Ã?Â¥

any idea how to do it and get � like I started with
EDIT:
OPPS posted in the wrong place

Edited by az on March 29, 2010, 8:22 p.m.

ReportQuote
#2
Are you sending the HTML in the right encoding?

Have I helped you? Do you like my add-ons?
Would you consider donating to show your appreciation for my efforts?

/images/paypal.png
ReportQuote
#3
i am using the get method
would i need to set
"Content-Type" to "application/x-www-form-urlencoded"
*go to try this*
edit:
thanks for moving this
still not working
GM test script
	GM_xmlhttpRequest({
		method: "GET",
		url: 'http://127.0.0.1/index.php?x='+encodeURIComponent('�'),//%E2%99%A5
		headers: {
			"Content-Type": "application/x-www-form-urlencoded"
		},
		onload: function(r){}
	});

store urldecode($_GET) in database
i end up Ã?¢ââ??¢Ã?Â¥ in the database

Edited by az on March 30, 2010, 7:55 p.m.

ReportQuote
#4
Well not exactly, more like say:
Content-Type: text/html; charset=UTF-8

There I am actually setting the encoding to UTF-8. Which is what this forum is using and why it displays right here. If I force the page to display with ISO-8859-1 (the default) it gives the funny characters you see.

If your going to do much work with characters like that, I recommend you don't use PHP, as it does not natively support unicode.

Have I helped you? Do you like my add-ons?
Would you consider donating to show your appreciation for my efforts?

/images/paypal.png
ReportQuote
#5
i would rather convert it back before storing it in the database less character usage that way
i could sore then escaped and un-escape them client side with js not the best way to do this
i can i make the php support unicode
headers: {
	"Content-Type": "text/html; charset=UTF-8"
},

changing that in the js did not change anything other than the header of course
ReportQuote
#6
Storing it as UTF-8 will not use extra characters in the database. Can I see what page your getting the scrambled data on, so I can see for myself what is going on?

Have I helped you? Do you like my add-ons?
Would you consider donating to show your appreciation for my efforts?

/images/paypal.png
ReportQuote
#7
http://127.0.0.1/index.php
not that that is useful
this will reproduce the issue I am having
index.php:
echo urldecode($_GET["x"])// is stored in the database not the escaped character string

greasemonkey_test.user.js:
GM_xmlhttpRequest({
	method: "GET",
	url: 'http://127.0.0.1/?x='+encodeURIComponent('�'),
	headers: {
		"Content-Type": "application/x-www-form-urlencoded"
	},
	onload: function(r){alert(r.responseText)}
});

browser:
firefox 3.6.2
OS:
Win XP home (32bit)
server setup:
xampp 1.7.1

Edited by az on March 31, 2010, 8:24 p.m.

ReportQuote
#8
What happens if the PHP is changed to:
header('Content-type: text/html; charset=UTF-8');
echo urldecode($_GET["x"]);

Have I helped you? Do you like my add-ons?
Would you consider donating to show your appreciation for my efforts?

/images/paypal.png
ReportQuote
#9
i had to adjust the 1st line order but it works thanks
this did not work (saw that coming)
<html><head></head><body><?
header('Content-type: text/html; charset=UTF-8');

this does work
<?
header('Content-type: text/html; charset=UTF-8');
echo '<html><head></head><body>';
ReportQuote

Thread Closed