Convert a string to number and back to string?

A string-to-number encoder as one-liner (PHP 5.3 style):

$numbers = implode(array_map(function ($n) { return sprintf('%03d', $n); },
                          unpack('C*', $str)));

It simply converts every byte into its decimal number equivalent, zero-padding it to a fixed length of 3 digits so it can be unambiguously converted back.

The decoder back to a string:

$str = implode(array_map('chr', str_split($numbers, 3)));

Example text:

Wörks wíth all ストリングズ
087195182114107115032119195173116104032097108108032227130185227131136227131170227131179227130176227130186


You can't just ORD chars into a string of numbers and expect it to come back because some chars may be on 2 characters and others 3.

For example:

Kang-HO will give you: 10797106103457279

Now how do you know it's not: 10-79-71-0-61-0-34-57-27-9?

You need to either pad all your numbers in 3 number codes and thus get: 107097106103045072079 and then break it apart in blocks of 3 numbers and then ASC them back...