473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

java to php code conversion

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
3 3937
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
14,534 Expert Mod 8TB
You have posted this in the Aticles section. This question is being moved to the PHP forum.

ADMIN
May 9 '07 #3
code green
1,726 Expert 1GB
Lets have a look at what you have done so far, then we can try and put it right
May 10 '07 #4

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

Similar topics

5
by: Roy Schestowitz | last post by:
Hi, I have asked this question in a C++ newsgroup, but I did not get quite the answer that I had hoped for. I would like to find out if there are tools which make large transitions from C++ to...
0
by: Charles Atwood | last post by:
I am trying to use the Java Language Conversion Assistant 2.0 with Visual Studio .NET 2003 on Windows 2000 Server SP4 and .NET framework 1.1 to convert some java files to C#. I go through all the...
7
by: jeff | last post by:
We have a library written in Java that we need to port to .NET (and we need to maintain both versions of the library). I've done some preliminary research on approaches to this but none of them...
2
by: Barney | last post by:
I have to convert a Java app to .NET, i found and used the conversion tool which converts java to C#, but it only converted about 10% of it, how hard would it be to re-write the java app and keep...
5
by: Michael Murphy | last post by:
Hi, could someone help me along with a Java to VB.Net conversion. Here is the java code private sub test1() throws Exception { //code in here }
1
by: Jimmy Zhang | last post by:
Hi, I was using JLCA to convert some code to C# and app performance just dropped a bit, I am wondering if any one can point me to some good reference on C# performance tuning tricks... Cheers, jz
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
34
by: Anthony Irwin | last post by:
Hi All, I am currently trying to decide between using python or java and have a few quick questions about python that you may be able to help with. #1 Does python have something like javas...
9
by: =?Utf-8?B?RmxhdmVsbGUgQmFsbGVt?= | last post by:
Apparently the Java Conversion tool that used to be in Visual Studio 2005 is no longer supported in Visual Studio 2008. Anyone have any suggestions on how to convert a Java program to C# in Visual...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.