views:

54

answers:

3

Hi everyone,

my application geting Text from a input field an post it over ajax to a php file for saving it to db.

var title = encodeURIComponent($('#title').val());

if I escape() the title it is all OK but i have Problems with "+" character. So i use the encodeURIComponent().

Now i habe a Problem with german special characters like "ö" "ä" "ü" they will be displayed like a crypdet something....

Have some an idea how can i solve this problem?

Thx

A: 

Try replacing that characters, not escaping...

Otar
A: 

You might use escape("AbcÄüö") and you would get "Abc%C4%FC%F6"

In php you could then use urldecode($myValue) to get "AbcÄüö" again

Ghommey
If you escape you will get problems with "+" character
Fincha
What do you mean by problems?
Ghommey
+1  A: 

I suppose this has to do with encoding : your HTML page might be using UTF-8, and the special characters are encoded like this :

>>> encodeURIComponent('ö');
"%C3%B6"

When your PHP page receives this, it has to know it's UTF-8, and deal with it as UTF-8 -- which means that everything on the server-side has to work with UTF-8 :

  • PHP code must use functions that can work with multi-byte characters
  • The database (db, tables, columns, ...) must use UTF-8 for storing data
  • When generating HTML pages, you need to indicate it's UTF-8 too, ...


For instance, if you are using var_dump() on the PHP side to display what's been sent from the client, don't forget to indicate that the generated page is in UTF-8, with something like this :

header('Content-type: text/html; charset=UTF-8');

Else, the browser will use it's default charset -- which is not necessarily the right one, and possibly display garbage.

Pascal MARTIN
DB and HTML works with uft-8, how can i decode %C3%B6 in normal characters?
Fincha
As you see %C3%B6 = ¶Á there 2 characters, %c3 and %b6 ... that is the problem
Fincha
Actually, `%C3%B6` doesn't mean two characters ; it means two bytes, but the way those two bytes are interpreted depend on the charset ;;; If you are working with UTF-8, which is a multi-byte charset *(each character can take up to 4 bytes)*, those two bytes actually represent only 1 character ;-) ;;; if you make sure everything is interpreted as UTF-8, you'll be fine ;-)
Pascal MARTIN
How can i say the php "this is a uft8 string"? The Db works with utf8_bin
Fincha