What is the PHP equivalent for the following C# code
Encoding.ASCII.GetBytes(vstrEncryptionKey.ToCharArray())
where vstrEncryptionKey
is a variable?
Use the ord
function (http://php.net/ord) and the mb_strlen
function http://php.net/manual/en/function.mb-strlen.php)
<?php
$var = $vstrEncryptionKey;
for($i = 0; $i < mb_strlen($var, 'ASCII'); $i++)
{
echo ord($var[$i]);
}
?>
This is modified code from the answer given in How do I get the byte values of a string in PHP?