X
X
Xakephp2014-10-05 15:51:45
PHP
Xakephp, 2014-10-05 15:51:45

How to make text shorter?

There is this code (demonstrated below) that changes the text in Unicode and you need something new . It is
necessary that each text be transformed more briefly, the text will be written in arrays.
Now the word example = 108710881080108410771088
the problem is that Unicode is too long
here is the code that converts to Unicode you may not need it

function mb_str_split($string) {
    return array_map(function ($i) use ($string) {
          return mb_substr($string,$i,1,"utf-8");
    }, range(0, mb_strlen($string, "utf-8")-1));
}

function incode($string) {
  return array_reduce(mb_str_split($string), function($result, $e) {
    $convertedString = unpack("N", mb_convert_encoding($e, "UCS-4BE", "UTF-8"));
                return $result . (is_array($convertedString) ? $convertedString[1] : '');
  }, "");
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2014-10-05
@Xakephp

I didn’t understand the task from the word at all, but if we start from the “encode shorter” condition, then you can do this:

function incode($string) {
  return $string;
}

instead of 108710881080108410771088 it will return "example" - 2 times shorter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question