Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8104847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:59:29+00:00 2026-06-05T23:59:29+00:00

I have a javascript function which I wants in PHP, Here is my JavaScript

  • 0

I have a javascript function which I wants in PHP, Here is my JavaScript function:

<script type="text/javascript">
                    str = '242357de5b105346ea2059795682443';
                    str_overral = str;
                    str_overral = str_overral.replace(/[^a-z0-9]/gi, '').toLowerCase();
                    str_res='';
                    for (i=0; i<str_overral.length; i++) {
                        l=str_overral.substr(i,1);
                        d=l.charCodeAt(0);
                        if ( Math.floor(d/2) == d/2 ) {
                            str_res+=l;
                        } else {
                            str_res=l+str_res;
                        }
                    }
                    document.write('<in');
                    document.write('put type="hidden" name="myInput" value="'+str_res+'" />');
                </script>

and above JavaScript function generates this string for myInput: 359795ae3515e753242db0462068244

And this I tried with PHP:

    $str = '242357de5b105346ea2059795682443';
    $str_overral = preg_replace('/[^a-z0-9]/i', '',$str);
    $str_overral = strtolower($str_overral);
    $str_res=''; 
    for ($i=0; $i<strlen($str_overral); $i++) {
        $l= substr($str_overral,$i,1);
        // PHP does not have charCodeAt() function so i used uniord()
        $d = uniord($l);
        if((floor($d)/2) == ($d/2))
            $str_res.=$l;
        else
            $str_res.= $l.$str_res;
    }
    echo $str_res;

function uniord($c) {
        $h = ord($c{0});
        if ($h <= 0x7F) {
            return $h;
        } else if ($h < 0xC2) {
            return false;
        } else if ($h <= 0xDF) {
            return ($h & 0x1F) << 6 | (ord($c{1}) & 0x3F);
        } else if ($h <= 0xEF) {
            return ($h & 0x0F) << 12 | (ord($c{1}) & 0x3F) << 6
                                     | (ord($c{2}) & 0x3F);
        } else if ($h <= 0xF4) {
            return ($h & 0x0F) << 18 | (ord($c{1}) & 0x3F) << 12
                                     | (ord($c{2}) & 0x3F) << 6
                                     | (ord($c{3}) & 0x3F);
        } else {
            return false;
        }
    }   

and above PHP code generates this string: 242357de5b105346ea2059795682443
so basically PHP just return $string as is.

As PHP does not have charCodeAt() function I found a solution here UTF-8 Safe Equivelant of ord or charCodeAt() in PHP , But that does not work for me, I even tried solution posted by ‘hakre’ in same thread.

Thank you for any kind of help.

UPDATE SOLUTION:

Here was fix:

if($d%2 == 0)
    $str_res.=$l;
else
    $str_res = $l.$str_res;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:59:30+00:00Added an answer on June 5, 2026 at 11:59 pm
    if((floor($d)/2) == ($d/2))
    

    You have a ) in the wrong place. It should be after the first /2, not before it.

    It could be made more efficient with if($d%2 == 0)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a header file i have which is populated by PHP: <script type=text/javascript> var
I have this piece of code written in jQuery and PHP: <script type=text/javascript> $(document).ready(function(){
I have a script embedded in a page, which is as follows: <script type=text/javascript>
I have a JavaScript function which is quite long and performs a number of
I have a javascript function which needs to do a numerical calculation. Some of
Ok, i have a javascript function which toggles the innerhtml of a div tag
I have a javascript function from which I need to call a controller action
I have a small javascript function which opens an url in a new tab:
I have a javascript function for checking errors which I am calling on OnClicentClick
Can I´m asking for advice. I have function which should return javascript object function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.