|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
hello
does php have any built-in functions to convert post data from whatever format it arrives in to whatever format i wish? example: i use iso-8859-1 internally, and even specify accept-charset=iso-8859-1 in my html, but some browsers (phones) send utf-8 anyway. do i have to manually check if CONTENT_TYPE says "utf-8" and then convert the $_POST array elements one by one, or does php have any built-in functions to ease this? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Olav Mørkrid wrote:
> hello > > does php have any built-in functions to convert post data from > whatever format it arrives in to whatever format i wish? > > example: > > i use iso-8859-1 internally, and even specify > accept-charset=iso-8859-1 in my html, but some browsers (phones) send > utf-8 anyway. > > do i have to manually check if CONTENT_TYPE says "utf-8" and then > convert the $_POST array elements one by one, or does php have any > built-in functions to ease this? That's interesting question. Do you generate the pages, respectively do you specify something like this - <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> My experience is that this does not affect only the displayed characters, but the way the form fields are transported. But perhaps I am wrong, Iv |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> > My experience is that this does not affect only the displayed > characters, but the way the form fields are transported. > > But perhaps I am wrong, > Iv This works for me as well. Put in utf-8 and you should be good to go. You don't -technically- need to even change your database fields or anything; MySQL will take the utf-8 content and treat it like normal binary content. (However, if you want to modify the data in MySQL, then you might want to make sure you have all the right character sets and stuff...) I've had 100% success with just inserting and selecting info back and forth from MySQL and displaying it on the page, with the proper <meta> tag. Works like a charm in all languages attempted - English, Chinese (both Simplified and Traditional), Russian, etc... it will look funky if you view it directly in MySQL command line client or if you forget the utf-8 tag though (unless your TERM + column and connection is set properly) |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
i specify iso-8859-1 in both header and body:
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1"/> <form action="/" method="post" accept-charset="iso-8859-1"> if two different people post the norwegian phrase "Godt nytt år" (happy new year), it may appear in the following variations: [CONTENT_TYPE] => application/x-www-form-urlencoded;charset=iso-8859-1 $_POST["input"] = "Godt nytt år" [CONTENT_TYPE] => application/x-www-form-urlencoded;charset=utf-8 $_POST["input"] = "Godt nytt Ã¥r" i was just wondering if php had some setting or function that would make it auto-convert $_POST data into one specific encoding. otherwise i seem forced to do something like this in the beginning of my php script: if(ereg("utf-8", $_SERVER["CONTENT_TYPE"])) { foreach($_POST as $key => $value) $_POST["key"] = convert_utf8_to_iso8859($value); } |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
I have to ask... WHY are you forcing ISO-8859-1? If anything, you should be
forcing UTF-8. Then you can send, receive, and store data in UTF-8 ad cover most human languages without having to change character set. On Monday 07 January 2008, Olav Mørkrid wrote: > i specify iso-8859-1 in both header and body: > > <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1"/> > <form action="/" method="post" accept-charset="iso-8859-1"> > > if two different people post the norwegian phrase "Godt nytt år" > (happy new year), it may appear in the following variations: > > [CONTENT_TYPE] => application/x-www-form-urlencoded;charset=iso-8859-1 > $_POST["input"] = "Godt nytt år" > > [CONTENT_TYPE] => application/x-www-form-urlencoded;charset=utf-8 > $_POST["input"] = "Godt nytt Ã¥r" > > i was just wondering if php had some setting or function that would > make it auto-convert $_POST data into one specific encoding. otherwise > i seem forced to do something like this in the beginning of my php > script: > > if(ereg("utf-8", $_SERVER["CONTENT_TYPE"])) { > foreach($_POST as $key => $value) > $_POST["key"] = convert_utf8_to_iso8859($value); > } -- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Olav Mørkrid wrote:
> i specify iso-8859-1 in both header and body: > > <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1"/> > <form action="/" method="post" accept-charset="iso-8859-1"> > > if two different people post the norwegian phrase "Godt nytt år" > (happy new year), it may appear in the following variations: > > [CONTENT_TYPE] => application/x-www-form-urlencoded;charset=iso-8859-1 > $_POST["input"] = "Godt nytt år" > > [CONTENT_TYPE] => application/x-www-form-urlencoded;charset=utf-8 > $_POST["input"] = "Godt nytt Ã¥r" Hm... What User Agents? Are there User Agents that do not follow the instructions? > i was just wondering if php had some setting or function that would > make it auto-convert $_POST data into one specific encoding. I have been banging my head over this some time ago. The main problem I had at that time is that I could not find a reliable way to detect the incoming encoding, which is the base of conversion. If the User Agents are so unstable, you can't expect consistent error, but you should be prepared for all kind of deviations. > otherwise > i seem forced to do something like this in the beginning of my php > script: > > if(ereg("utf-8", $_SERVER["CONTENT_TYPE"])) { > foreach($_POST as $key => $value) > $_POST["key"] = convert_utf8_to_iso8859($value); > } As said above, you assume that the inconsistency will persist. And this assumption is not stable, as it seems the User Agents do not follow the instructions you sent to them. I would agree with the others and advice you to switch to UTF-8 - this is the only encoding, where you can handle multiple alphabets _without_ knowing which alphabet it is. Iv |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
To author:
You'r going the wrong way. Make your page utf-8, all text on it. Set utf-8 encoding and treat all incoming data as UTF-8. If some agent (definetly not some browser - they all know UTF-8) doesn't understand that (that could be some "hacker" writing it's own bot) - that's his problem. Then you will get all data incoming in utf-8 and you can just add, modify and select it in and from database (don't forget to set database and tables to UTF-8, that is default in MySQL 4.1 and above). If you have to deal with utf-8 data, you need the mb_string extension, see manual. |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
Olav Mørkrid wrote:
> i specify iso-8859-1 in both header and body: > > <meta http-equiv="Content-type" content="text/html; > charset=iso-8859-1"/> <form action="/" method="post" > accept-charset="iso-8859-1"> Have you checked 1) what the webserver sends in the header and 2) what the browser actually uses? I'm pretty certain I've had issues where the meta tags were fine, but the server overrode me settings in the header. /Per Jessen, Zürich |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
At 11:57 AM +0200 1/8/08, Arvids Godjuks wrote:
>To author: > >You'r going the wrong way. >Make your page utf-8, all text on it. Set utf-8 encoding and treat all >incoming data as UTF-8. If some agent (definetly not some browser - they all >know UTF-8) doesn't understand that (that could be some "hacker" writing >it's own bot) - that's his problem. Then you will get all data incoming in >utf-8 and you can just add, modify and select it in and from database (don't >forget to set database and tables to UTF-8, that is default in MySQL 4.1 and >above). > >If you have to deal with utf-8 data, you need the mb_string extension, see >manual. Good advice. Last night I read a chapter in the book "Core Web Application Development with PHP and MYSQL" by Wandschneider who said basically that -- a good read, btw. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
On Jan 8, 2008 1:31 PM, tedd <tedd.sperling@gmail.com> wrote:
> Last night I read a chapter in the book "Core Web Application > Development with PHP and MYSQL" by Wandschneider who said basically > that -- a good read, btw. I'm guess it was his name which comprised the first chapter. -- Daniel P. Brown [Phone Numbers Go Here!] [They're Hidden From View!] If at first you don't succeed, stick to what you know best so that you can make enough money to pay someone else to do it for you. |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
the user agents in question are various mobile phones, which as you
might guess are premature technology and have their own ways with things. here is an example posting from a Samsung D600 which insists on posting form data in UTF-8 even though i serve it ISO-8859-1 and it claims to support all character sets. [_POST] => Array ( [message] => Norwegian characters: øá ) [_SERVER] => Array ( [HTTP_ACCEPT_CHARSET] => * [CONTENT_TYPE] => application/x-www-form-urlencoded; charset=utf-8 [HTTP_USER_AGENT] => SAMSUNG-SGH-D600E/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 ) i would consider switching to utf-8 if i knew how make the windows version of emacs work fine with utf-8 text files (and still work with iso-8859-1 files as well). On 08/01/2008, Per Jessen <per@computer.org> wrote: > Olav Mørkrid wrote: > > > i specify iso-8859-1 in both header and body: > > > > <meta http-equiv="Content-type" content="text/html; > > charset=iso-8859-1"/> <form action="/" method="post" > > accept-charset="iso-8859-1"> > > Have you checked 1) what the webserver sends in the header and 2) what > the browser actually uses? I'm pretty certain I've had issues where > the meta tags were fine, but the server overrode me settings in the > header. > > > /Per Jessen, Zürich > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > |
|
![]() |
| Outils de la discussion | |
|
|