Does PHP have a function that searches for hexadecimal codes in a string and converts them to its char equivalents?
For example, I have a line containing the following
"Hello World \ x19s"
And I want to convert it to
"Hello World"
Thanks in advance.
This code converts "Hello World \ x27s" to "Hello World". It converts "\ x19" to the character "end of medium" since what 0x19 represents in ASCII.
$str = preg_replace('/\\\\x([0-9a-f]{2})/e', 'chr(hexdec($1))', $str);
Correct me if I am wrong, but I think you should change the callback as follows:
$str = preg_replace('/\\\\x([0-9a-f]{2})/e', 'chr(hexdec(\'$1\'))', $str);
, '=' (\ x3d), .
/e php- preg_replace_callback. :
preg_replace_callback('/\\\\x([0-9a-f]{2})/', function ($m) { return chr(hexdec($m[1])); }, $str );
/ e The modifier causes PHP errors. It is deprecated with new PHP updates. The correct way to convert hex codes to characters is:
$str = html_entity_decode($str, ENT_QUOTES | ENT_XML1, 'UTF-8');
This will turn 'into ' and &into & etc.
'
&
Source: https://habr.com/ru/post/1777156/More articles:Opening thousands of cURL handles without problems? (PHP) - phpfrom the end does not work, as I expect in position - lispWhat is the most efficient way to load a dictionary in Python? - pythonMonoDevelop Addon-ons as Eclipse - monodevelopthe compiler does not complain about a function that does not return a value - c ++C ++ Type of function CALLBACK - c ++Amazon SDB - Limits PUTs per second explained? - amazon-simpledbInitializing a Large Global Constant Object - c ++Feedback, resources and information for a declarative programming language - programming-languages | fooobar.comWhere can I download iPhone 3.1? - iphoneAll Articles