Answer the question
In order to leave comments, you need to log in
How to decode string from hex? Who has experienced this?
Good afternoon.
It was required to pull out all articles from the table in a DB. There are a lot of articles, more than 20 thousand, dofig fields, I decided to upload everything in json format to a file, opened this file on a new site through file_get_contents, and went through the cycle, added all the articles to myself. I already did this before, so the code was ready, hence the solution. But if other tables were transferred perfectly, then here I ran into an encoding unknown to me. Instead of Russian titles and content - encoded text. I couldn't find anything on this topic.
Here's what the title of the article looks like:
0xd091d183d0bad0bcd0b5d0bad0b5d180d181d0bad0b8d0b520d0bad0bed0bdd182d0bed180d18b20d0b820d181d182d0b0d0b2d0bad0b820d0bdd0b020d181d0bfd0bed180d182
Answer the question
In order to leave comments, you need to log in
In short, I figured it out, partly thanks to the answer of galaxy (dude below), but due to the fact that he did not say the main thing, I will mark my answer as the solution.
This hash is really from hex. And indeed it is converted using the hex2bin() function.
BUT!
For some reason it is hashed so that the first 2 characters are superfluous: "0x". They need to be removed. Until you remove them, the function will not work, it will give an error: "Input string must be hexadecimal string".
Therefore, we do this:
$s = "0xd091d183d0bad0bcd0b5d0bad0b5d180d181d0bad0b8d0b520d0bad0bed0bdd182d0bed180d18b20d0b820d181d182d0b0d0b2d0bad0b820d0bdd0b020d181d0bfd0bed180d182";
$s = substr($s, 2, strlen($s));
$s = hex2bin($s);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question