S
S
seredaes2015-06-26 13:16:00
PHP
seredaes, 2015-06-26 13:16:00

PHP Convert string to UTF code?

I need to convert the string to this form:
366ef212c69c467f988052f53b4e80e6.png
Please help :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2015-06-26
@seredaes

function convert($str) {
    $str = mb_convert_encoding($str , 'UTF-32', 'UTF-8'); // Big endian
    $t = unpack('N*', $str);
    $t = array_map(function($n) { return "&#$n;"; }, $t);

    return join('', $t);
}

var_dump(convert('foo bar')); // string(39) "foo bar"

If you need a unicode sequence - see this question on stackoverflow and apply the reverse transformation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question