By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,965 Members | 1,702 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,965 IT Pros & Developers. It's quick & easy.

java to php code conversion

P: 7
Can anyone help me how to convert this java function to PHP


function dec2hex ( textString ) {
return (textString+0).toString(16).toUpperCase();
}

function convertChar2CP ( textString ) {
var outputString = "";
var haut = 0;
var n = 0;
for (var i = 0; i < textString.length; i++) {
var b = textString.charCodeAt(i); // alert('b:'+dec2hex(b));
if (b < 0 || b > 0xFFFF) {
outputString += '!erreur ' + dec2hex(b) + '!';
}
if (haut != 0) {
if (0xDC00 <= b && b <= 0xDFFF) {
outputString += dec2hex(0x10000 + ((haut - 0xD800) << 10) + (b - 0xDC00)) + ' ';
haut = 0;
continue;
} else {
outputString += '!erreur ' + dec2hex(haut) + '!';
haut = 0;
}
}
if (0xD800 <= b && b <= 0xDBFF) {
haut = b;
} else {
outputString += dec2hex(b) + ' ';
}
}
return( outputString.replace(/ $/, '') );
}


Thank you in advance
May 9 '07 #1
Share this Question
Share on Google+
3 Replies


P: 7
Can anyone help me convert this java functions to PHP, it will be a great help for me.

thank you in advance.


========== the function ==========

function dec2hex ( textString ) {
return (textString+0).toString(16).toUpperCase();
}

function convertChar2CP ( textString ) {
var outputString = "";
var haut = 0;
var n = 0;
for (var i = 0; i < textString.length; i++) {
var b = textString.charCodeAt(i); // alert('b:'+dec2hex(b));
if (b < 0 || b > 0xFFFF) {
outputString += '!erreur ' + dec2hex(b) + '!';
}
if (haut != 0) {
if (0xDC00 <= b && b <= 0xDFFF) {
outputString += dec2hex(0x10000 + ((haut - 0xD800) << 10) + (b - 0xDC00)) + ' ';
haut = 0;
continue;
} else {
outputString += '!erreur ' + dec2hex(haut) + '!';
haut = 0;
}
}
if (0xD800 <= b && b <= 0xDBFF) {
haut = b;
} else {
outputString += dec2hex(b) + ' ';
}
}
return( outputString.replace(/ $/, '') );
}

function dec2hex4 ( textString ) {
var hexequiv = new Array ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
return hexequiv[(textString >> 12) & 0xF] + hexequiv[(textString >> 8) & 0xF] + hexequiv[(textString >> 4) & 0xF] + hexequiv[textString & 0xF];
}

function convertCP2UTF16 ( textString ) {
var outputString = "";
textString = textString.replace(/^\s+/, '');
if (textString.length == 0) { return ""; }
textString = textString.replace(/\s+/g, ' ');
var listArray = textString.split(' ');
for ( var i = 0; i < listArray.length; i++ ) {
var n = parseInt(listArray[i], 16);
if (i > 0) { outputString += ' ';}
if (n <= 0xFFFF) {
outputString += dec2hex4(n);
} else if (n <= 0x10FFFF) {
n -= 0x10000
outputString += dec2hex4(0xD800 | (n >> 10)) + ' ' + dec2hex4(0xDC00 | (n & 0x3FF));
} else {
outputString += '!erreur ' + dec2hex(n) +'!';
}
}
return( outputString );
}
May 9 '07 #2

MMcCarthy
Expert Mod 10K+
P: 14,534
You have posted this in the Aticles section. This question is being moved to the PHP forum.

ADMIN
May 9 '07 #3

code green
Expert 100+
P: 1,726
Lets have a look at what you have done so far, then we can try and put it right
May 10 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.