Converting javascript code to PHP charCodeAt() issue
<p>I have a javascript function which I wants in PHP, Here is my JavaScript function:</p>

<pre><code>&lt;script type="text/javascript"&gt;
                    str = '242357de5b105346ea2059795682443';
                    str_overral = str;
                    str_overral = str_overral.replace(/[^a-z0-9]/gi, '').toLowerCase();
                    str_res='';
                    for (i=0; i&lt;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('&lt;in');
                    document.write('put type="hidden" name="myInput" value="'+str_res+'" /&gt;');
                &lt;/script&gt;
</code></pre>

<p>and above JavaScript function generates this string for myInput: <code>359795ae3515e753242db0462068244</code></p>

<p>And this I tried with PHP:</p>

<pre><code>    $str = '242357de5b105346ea2059795682443';
    $str_overral = preg_replace('/[^a-z0-9]/i', '',$str);
    $str_overral = strtolower($str_overral);
    $str_res=''; 
    for ($i=0; $i&lt;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 &lt;= 0x7F) {
            return $h;
        } else if ($h &lt; 0xC2) {
            return false;
        } else if ($h &lt;= 0xDF) {
            return ($h &amp; 0x1F) &lt;&lt; 6 | (ord($c{1}) &amp; 0x3F);
        } else if ($h &lt;= 0xEF) {
            return ($h &amp; 0x0F) &lt;&lt; 12 | (ord($c{1}) &amp; 0x3F) &lt;&lt; 6
                                     | (ord($c{2}) &amp; 0x3F);
        } else if ($h &lt;= 0xF4) {
            return ($h &amp; 0x0F) &lt;&lt; 18 | (ord($c{1}) &amp; 0x3F) &lt;&lt; 12
                                     | (ord($c{2}) &amp; 0x3F) &lt;&lt; 6
                                     | (ord($c{3}) &amp; 0x3F);
        } else {
            return false;
        }
    }   
</code></pre>

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

<p>As PHP does not have charCodeAt() function I found a solution here <a href="http://stackoverflow.com/questions/10333098/utf-8-safe-equivelant-of-ord-or-charcodeat-in-php">UTF-8 Safe Equivelant of ord or charCodeAt() in PHP</a> , But that does not work for me, I even tried solution posted by 'hakre' in same thread.</p>

<p>Thank you for any kind of help.</p>

<p>UPDATE SOLUTION:</p>

<p>Here was fix:</p>

<pre><code>if($d%2 == 0)
    $str_res.=$l;
else
    $str_res = $l.$str_res;
</code></pre>
