Can anybody explain why this accented character routine works?

This is a discussion on Can anybody explain why this accented character routine works? within the PHP General forums, part of the PHP Programming Forums category; For a while I had been needing a process to allow French-speaking users to send text, including accented characters, ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-30-2007
maxwells@gmail.com
 
Posts: n/a
Default Can anybody explain why this accented character routine works?

For a while I had been needing a process to allow French-speaking
users to send text, including accented characters, to the server via
AJAX. These characters would then be left as normal accented
characters, ready to be written to a text file, or prepared for HTML
files as HTML entities.

I found a way to do it by trial and error, and it works beautifully.
Trouble is, I am writing an AJAX manual and I am supposed to guide
readers on this process - but I can't really explain why it works, as
it is not particularly intuitive. Can anybody help?

The HTML file has a meta tag in the header with the following:

content="text/html;charset=utf-8"

The Javascript sends the text after delimiting it as follows:

escape($t);

In the PHP file the following serious of functions is applied:

$t=utf8_encode($t);
$t=utf8_decode($t);
$t=stripslashes($t);

After being encoded and decoded again the accented characters come
through brilliantly. I can then either write to a text file or prepare
the text for an HTML file as follows:

$t=htmlentities($t);

The thing I do not understand is why the need to encode and then
decode?

I would be very grateful if somebody could throw some light on this.

Thanks for you time,

Max

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:39 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0