Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2005

    Unanswered: converting to hex(unicode)

    i have the following code for converting to hex(unicode) its working fine but I need this same program in PHP, i mean instead of javascript i need that function in php,

    i think its better if u copy the follwing code and then see it in browser to understand my problem.

    thanks in advance

    ************************************************** *
    <HEAD><TITLE>Unicode 2 converter</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
    .titre1 {
    font-family: Geneva, Arial, Helvetica, sans-serif;
    font-size: 18px;
    font-weight: bold;
    color: #225E7D;
    font-style: italic;
    var submitcount;
    function reset()

    function textCounter(field, countfield) {
    countfield.value = field.value.length;
    function textCountDown(field, countfield, maxlimit) {
    if (field.value.length > maxlimit)
    field.value = field.value.substring(0, maxlimit);
    countfield.value = maxlimit - field.value.length;

    <SCRIPT language=javascript type=text/javascript>
    //Fonction de formatage
    function formatage (myvar, longueur)
    while (myvar.length < longueur)
    myvar = "0"+myvar
    return myvar;

    function encode(){
    if(document.forms[0].ascii.value!= ''){
    var vText = document.forms[0].ascii.value;
    document.forms[0].hex.value = convertToHex(vText);
    function convertToHex(num) {
    var hex = '';
    for (i=0;i<num.length;i++)
    hex += formatage("0" + num.charCodeAt(i).toString(16).toUpperCase(),4);
    return hex;


    <META content="Microsoft FrontPage 4.0" name=GENERATOR></HEAD>
    <FORM name="blah" action=""><B>Arabic Text</B><BR>
    <textarea class="titre1" onkeydown=textCounter(this.form.ascii, mLen); onkeyup=textCounter(this.form.ascii,this.form.remL en); name="ascii" cols="75" rows="1"></textarea>
    &nbsp; <BR>
    <INPUT tabIndex=2 readOnly maxLength=3 size=5 value=0 name="remLen">
    <input name="hex" type="text" value="" size="75">
    &nbsp; <BR>
    <input name="reset" type="reset" value=Clear>
    <INPUT name="button" type=button onclick=encode() value=Submit>

  2. #2
    Join Date
    Jan 2004
    I have a doubt in what you wanted to say or in what you wanted to do.
    As you say that you want the hex(unicode) (Hexadecimal I hope). Then the program you done in JS is not it. You are just geting the ascii for a char and just formating it.
    If you want the hexadeciamal in PHP then here is the code
    echo $val."<br>"; // Please text
    echo hexdec($val); // Hexadecimal val
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <form action="" method="post">
    <input type="text" name="txt1" value="" />
    <input type="submit" name="submit" value="submit" />

    if this is not what you mean then please revert back.

    Freelance and Technology Consultant
    Dreams are for ever

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts