简体   繁体   中英

how to chinese character add md5 function before chinese

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;

Use preg_replace_callback().

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM