Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in
/home/bateeqjg/public_html/news/wp-content/plugins/wp-syntax/wp-syntax.php on line
380
Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in
/home/bateeqjg/public_html/news/wp-content/plugins/wp-syntax/wp-syntax.php on line
380
Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in
/home/bateeqjg/public_html/news/wp-content/plugins/wp-syntax/wp-syntax.php on line
380
Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in
/home/bateeqjg/public_html/news/wp-content/plugins/wp-syntax/wp-syntax.php on line
380
Warning: Undefined array key "layout" in
/home/bateeqjg/public_html/news/wp-content/plugins/wp-about-author/wp-about-author.php on line
94
The following script will convert a string to the unicode values using javascript.
toUnicode is a extension to String.charCodeAt. The benefit of this function is that it returns the whole string a html unicode format.
Code
1
2
3
4
5
6
7
8
| String.prototype.toUnicode = function () {
var uni = [],
i = this.length;
while (i--) {
uni[i] = this.charCodeAt(i);
}
return "&#" + uni.join(';&#') + ";";
}; |
String.prototype.toUnicode = function () {
var uni = [],
i = this.length;
while (i--) {
uni[i] = this.charCodeAt(i);
}
return "&#" + uni.join(';&#') + ";";
};
Here’s another method that I thought of.
This one is using a regexp instead of a while loop and an array to form the unicode text.
1
2
3
4
5
| String.prototype.toUnicode = function () {
return this.replace(/./g, function (char) {
return "&#" + String.charCodeAt(char) + ";";
});
}; |
String.prototype.toUnicode = function () {
return this.replace(/./g, function (char) {
return "&#" + String.charCodeAt(char) + ";";
});
};
Usage:
Call toUnicode() on any string object.
Example:
1
| “<li/>”.toUnicode() //outputs: <li/> |
“<li/>”.toUnicode() //outputs: <li/>
However, if possible use document.createTextNode to insert text instead of converting it to unicode. Document.createTextNode is a native DOM method meaning it’s a lot faster, and easier to understand .
More infor here: document.createTextNode