This is a discussion on problem with php, json, browser, charset within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi, I am having a problem that is occuring when using php, json, utf-8 charset and IE7. It sounds ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
I am having a problem that is occuring when using php, json, utf-8 charset and IE7. It sounds like a browser (thus client side) problem but since it is occuring on a php driven website, I think the best help I can get is here. Given: webpage (valid XHTML, utf-8 charset) with form (I use the YUI dialog), using javascript I collect all the user input on the form, store it in an object, json encode it, send it to the server (AJAX GET, no form submit), json decode it, validate and sanitize it, store it in database when ok, otherwise create error message and send response back to the client. The problem occures when the user inputs coordinates like 53°16'35''. which is allowed. It works fine with FF, Safari and Opera, but not with IE7 (dont' know for IE6). Before the request is send to the server I visualize the json encoded information and the url with querystring in an alert and there is no difference here between IE7 and other browsers, but once it arrives on the server there is a difference: The first log line is the url + querystring, the second line is the result of $_GET['data']. When I use json_decode(stripslashes($data), true) the result is an associative array for FF, Safari and Opera, but empty for IE7. Where is the problem ? The charset, the urlencoding, ... ? FF, Safari, Opera log: 05/01/2008 17:37:45 - 192.168.1.2 - url = /webpage.php? action=modform&data={%22FormID%22:%2221%22,%22Fiel dsetID %22:%2287%22,%22XAttrID%22:%2218%22,%22Label%22:%2 2Max.%20longitude %22,%22Units%22:%22%22,%22ToolTip%22:%22Maximum%20 longitude %20(-180%20to%20180).%20Valid%20formats %20:%2053.5,%2053%C2%B016.2,%2053%C2%B016'20.5%20a nd%2053%C2%B016'22''. %22,%22MinValue%22:%22-180%22,%22MaxValue%22:%22a%22,%22ListID %22:%22%22,%22InputTypeID%22:%228%22,%22Multiple%2 2:false,%22Required %22:false} 05/01/2008 17:37:45 - 192.168.1.2 - get data = {\"FormID\":\"21\", \"FieldsetID\":\"87\",\"XAttrID\":\"18\",\"Label\" :\"Max. longitude\", \"Units\":\"\",\"ToolTip\":\"Maximum longitude (-180 to 180). Valid formats : 53.5, 53°16.2, 53°16\'20.5 and 53°16\'22\'\'.\",\"MinValue\": \"-180\",\"MaxValue\":\"a\",\"ListID\":\"\",\"InputTy peID\":\"8\", \"Multiple\":false,\"Required\":false} IE7 log: 05/01/2008 17:38:55 - 192.168.1.2 - url = /webpage.php? action=modform&data={"FormID":"21","FieldsetID":"8 7","XAttrID":"18","Label":"Max. %20longitude","Units":"","ToolTip":"Maximum%20long itude%20(-180%20to %20180).%20Valid%20formats%20:%2053.5,%2053°16.2,% 2053°16'20.5%20and %2053°16'22''.","MinValue":"-180","MaxValue":"a","ListID":"","InputTypeID":"8", "Multiple":false,"Required":false} 05/01/2008 17:38:55 - 192.168.1.2 - get data = {\"FormID\":\"21\", \"FieldsetID\":\"87\",\"XAttrID\":\"18\",\"Label\" :\"Max. longitude\", \"Units\":\"\",\"ToolTip\":\"Maximum longitude (-180 to 180). Valid formats : 53.5, 53°16.2, 53°16\'20.5 and 53°16\'22\'\'.\",\"MinValue\": \"-180\",\"MaxValue\":\"a\",\"ListID\":\"\",\"InputTy peID\":\"8\", \"Multiple\":false,\"Required\":false} thanx in advance, Pugi! |
|
|||
|
I've expiremented a bit with escape for javascript and urlencode for
PHP. They have a different outcome for ° (symbol for degrees): javascript: %B0 PHP: %C2%B0 Could this be the cause for my problems ? Pugi! On 5 jan, 18:04, "Pugi!" <pugin...@gmail.com> wrote: > Hi, > > I am having a problem that is occuring when using php, json, utf-8 > charset and IE7. > It sounds like a browser (thus client side) problem but since it is > occuring on a php driven website, I think the best help I can get is > here. > Given: webpage (valid XHTML, utf-8 charset) with form (I use the YUI > dialog), using javascript I collect all the user input on the form, > store it in an object, json encode it, send it to the server (AJAX > GET, no form submit), json decode it, validate and sanitize it, store > it in database when ok, otherwise create error message and send > response back to the client. > The problem occures when the user inputs coordinates like 53°16'35''. > which is allowed. It works fine with FF, Safari and Opera, but not > with IE7 (dont' know for IE6). Before the request is send to the > server I visualize the json encoded information and the url with > querystring in an alert and there is no difference here between IE7 > and other browsers, but once it arrives on the server there is a > difference: |
|
|||
|
Pugi! wrote:
> I've expiremented a bit with escape for javascript and urlencode for > PHP. > They have a different outcome for ° (symbol for degrees): > javascript: %B0 > PHP: %C2%B0 > Could this be the cause for my problems ? Sure that will make a difference, I guess you have UTF-8 on the PHP side while on the javascript uses ISO8859-1 -- //Aho |
|
|||
|
On 5 jan, 20:40, "J.O. Aho" <u...@example.net> wrote:
> Pugi! wrote: > > I've expiremented a bit with escape for javascript and urlencode for > > PHP. > > They have a different outcome for ° (symbol for degrees): > > javascript: %B0 > > PHP: %C2%B0 > > Could this be the cause for my problems ? > > Sure that will make a difference, I guess you have UTF-8 on the PHP side while > on the javascript uses ISO8859-1 > > -- > > //Aho No both have utf-8. For JSON I used a script I found on the internet and the YUI JSON (beta), both have same errors. There is something in the way IE7 sends the data that makes it impossible to process by json_decode. Using escape en urldecode, nothing works anymore. Any ideas ? Pugi! |