0

Hi all I want add md5 to chinese character, but not working

ex: 你好,我是Jack!

to: df1fd9101108b40d26977a8d0bb9fd1e-你, ac2c8f13c6e60810197b19d683f5f184-好, 16815254531798dc21ee979d1d9c6675-我, 0a60ac8f02ccd2cf723f927284877851-是, Jack!

My code:

$data = "你好,我是Jack!";

$data = preg_replace('/(\p{Han}+)/u',md5('$1')-$1,$data);

echo $data;

1 Answer 1

0

Use preg_replace_callback().

$data = "你好,我是Jack!";

$data2 = preg_replace_callback(
  '/(\p{Han})/u',
   function($matches){return md5($matches[1])."-".$matches[1];},
  $data
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.