How do I get the byte values of a string in PHP?

lynn picture lynn · Feb 26, 2009 · Viewed 50.8k times · Source

Say I have a string in php, that prints out to a text file like this:

nÖ§9q1Fª£

How do I get the byte codes of this to my text file rather than the funky ascii characters?

Answer

Gautam picture Gautam · Feb 26, 2009

Use the ord function

http://ca.php.net/ord

eg.

<?php
$var = "nÖ§9q1Fª£ˆæÓ§Œ_»—Ló]j";

for($i = 0; $i < strlen($var); $i++)
{
   echo ord($var[$i])."<br/>";
}
?>