PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 20, 2022

[FIXED] how to chinese character add md5 function before chinese

 November 20, 2022     php, preg-replace     No comments   

Issue

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;

Solution

Use preg_replace_callback().

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

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


Answered By - jspit
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing