Php regular expression replacement

Source: Internet
Author: User
Tags php regular expression
Php regular expression replacement $ array = array ('AAA', 'bbbbbbbb', 'cccccccccc', 'ddddddddddd ');
$ Str = 'abcdej {$ array} jdijij ';

$ Str = preg_replace ("/^ \{\$ (.*?) \} $/I ", 'print _ r (\ 1); ', $ str );
Print_r ($ str );

How to replace the regular expression with {print_r ($ array ??
How do I write regular expressions such as for while foreach ???


Reply to discussion (solution)

$ Str = 'abcdej {$ array} jdijij '; $ str = preg_replace ('/\ {(\ $. + ?) \}/','

 ', $ Str); echo $ str;
Abcdej Jdijij

When the rule string is enclosed in double quotation marks
$ Str = 'abcdej {$ array} jdijij'; $ str = preg_replace ("// \{ (\\\$. + ?) \}/",'

 ', $ Str); echo $ str;

The results of \\$ and \\\$ are the same. I know that \ is an escape, but only two are allowed. but in many places, three are written. why?

This is a test result. for example, you have to write three in my environment.

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.