Ask God for help, about regular expressions

Source: Internet
Author: User
$str = "fsafsaf<{0}>54a<{1}>u7ygda<{2}>kklaoda<{3}>"; $char = Array (' A1 ', ' A2 ', ' A3 ', ' A4 '); $ Pattern = '/<\{(\d*) \}>/'; $replacement = ' $char [\\1] '; $newstr = Preg_replace ($pattern, $replacement, $STR); echo $ NEWSTR;


I want to replace the <{0}><{1}><{2}><{3}> in the $str with the $char array corresponding to the underlying value, can be replaced by my code above the output of fsafsaf$char[0]54a$ CHAR[1]U7YGDA$CHAR[2]KKLAODA$CHAR[3], did not take the value, on this issue card master, kneeling for guidance.


Reply to discussion (solution)

$pattern = '/<\{(\d*) \}>/e ';

$pattern = '/<\{(\d*) \}>/e ';

Thank you very much, this can be written, you can ask what is the meaning of an e?

Eval calculation expression string

Eval calculation expression string

Understand, thanks again!!

  • 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.