views:

853

answers:

2

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?

+3  A: 

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/>";
}
?>
Gautam
+1  A: 

Ord() does the trick with an ASCII-charset. If you, however, meddle with multibyte strings (like UTF-8), you're out of luck, and need to hack it yourself.

Henrik Paul