Please write a regular expression

Source: Internet
Author: User
Requirement for writing a regular segment: extract the content (including {literal} and {/literal}) between {liter} and {/literal} in a string }), then, encrypt the md5 value and put it back in the original place. I wrote $ str = "in this way, the company's eldest brother reterty {literal} jpojp {/literal} ojo needs to write a regular expression highly.
Requirement: extract the content between {liter} and {/liter} in a string (including {literal} and {/literal}), encrypt the md5 value, and put it back to the original location.

I wrote it like this.


$ Str = "reterty {literal} jpojp {/literal} ojojwr154654654wete fan {literal} tigang's identity {/literal} rowetw, Guangdong province ";


$ New_str = preg_replace ('/\ {literal \}(.*?) \ {\/Literal \}/isum ', md5 ("$1"), $ new_str );
Print_r ($ new_str );

In this case, the md5 values in the two {liter} are the same and I don't know where the error is. please modify it (use the preg_replace function)
------ Solution --------------------
$ New_str = preg_replace ('/\ {literal \}(.*?) \ {\/Literal \}/ise ', 'md5 ("$1")', $ str );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.