| ::: About this Blog ::: |
Welcome to Arul's Blog! Weblog on Multimedia,
 |
Flash MX |
 |
Director |
 |
Dreamweaver MX |
 |
And me :) |
Here I'm going to share my views, opinions and code with you all. |
| ::: Time Zone ::: |
All Times on this blog are
GMT + 5:30 Hours
(Indian Standard Time) |
|
Sunday, March 28, 2004
|
Code.Flash MX: ActionScript for handling HTML Escape Characters.
In my last post I've explained about Unicode notation handling. Now let's see how we can process HTML escape characters in the &#number; format. This format is used for placing Unicode characters in a plain HTML page (ANSI) without using UTF-8 Encoding
With the help of the actionscript below you can create a HTML editor in flash which can pass the escaped string to server side script for saving it as a plain HTML file which properly renders the Unicode characters in the browser.
function setMinimumDigits(num, digits) {
var str = num.toString();
while (str.length<digits) {
str = "0"+str;
}
return (str);
}
String.prototype.HTMLUnescape = function() {
var arr:Array = this.split("&#");
var l:Number = arr.length;
while (l--) {
var s = arr[l];
arr[l] = String.fromCharCode(parseInt(substring(s, 0, 4)))+substring(s, 6, -1);
}
return arr.join("");
};
String.prototype.HTMLEscape = function() {
var s:String = "";
for (var i = 0; i<this.length; i++) {
var d = this.charCodeAt(i);
if (d<127) {
s += this.charAt(i);
} else {
s += "&#"+setMinimumDigits(d, 4)+';';
}
}
return s;
};
Usage:
var test = "??pa??thu??kaa??p??pu";
//encoding
var encoded = test.HTMLEscape();
trace(encoded);
//traces "பாpaதுthuகாkaaப்pபுpu"
//
//decoding
trace(encoded.HTMLUnescape());
//traces "??pa??thu??kaa??p??pu"
posted by Arul
| link
| ^top
| next> |
add comment |
Tuesday, March 16, 2004
|
Code.Flash MX: ActionScript for Unicode Escape Notation handling.
When your back end does not give full support for Unicode ( like PHP, amfphp etc.,) you may use the following function to encode the characters as notations before sending it to server and decode the notations back to the characters before display.
It is the improved version of the code I used in my Unicode escape notations generator. Some people asked me to release the code, so here it is
function setMinimumDigits(num, digits) {
var str = num.toString();
while (str.length<digits) {
str = "0"+str;
}
return (str);
}
String.prototype.decodeNotation = function() {
var arr:Array = this.split("\\u");
var l:Number = arr.length;
while (l--) {
var s = arr[l];
arr[l] = String.fromCharCode(parseInt(substring(s, 0, 4), 16))+substring(s, 5, -1);
}
return arr.join("");
};
String.prototype.encodeNotation = function() {
var s:String = "";
for (var i = 0; i<this.length; i++) {
var d = this.charCodeAt(i);
var c = this.charAt(i);
if (d<127) {
s += c;
} else {
s += "\\u"+setMinimumDigits(d.toString(16).toUpperCase(), 4);
}
}
return s;
};
Usage:
var test = "பாpaதுthuகாkaaப்pபுpu";
//encoding
var encoded = test.encodeNotation();
trace(encoded);
//traces "\u0BAA\u0BBEpa\u0BA4\u0BC1thu\u0B95\u0BBEkaa\u0BAA\u0BCDp\u0BAA\u0BC1pu"
//
//decoding
trace(encoded.decodeNotation());
//traces "பாpaதுthuகாkaaப்pபுpu"
posted by Arul
| link
|<prev. | ^top
| next> |
add comment |
footnote:-
Also check the recent entries
and feel free to add your comments. I need your comments to improve this blog
|
|