Parsing variable names in PHP Custom Strings

Source: Internet
Author: User
To resolve variable names in PHP custom strings, you can customize the page title in the background. the custom content may contain variables, which are represented by {$ var, $ var indicates the variable name.

After the title field is saved to the database and extracted, it will not be used for parsing with the php variable name. it will directly output {$ var} instead of defining the string, when double quotation marks are used, {$ var} is automatically transformed into the corresponding variable content. here it is like a string defined by single quotation marks, so you need to parse it yourself.

Here, we use a regular expression to extract all {$ var} from the string and determine whether the corresponding variable exists. if so, replace the corresponding content with str_replace ().

The procedure is as follows:

 $ Value) {if (isset ($ value) {$ title = str_replace ($ match [0] [$ key], $ value, $ title );}} echo $ title;

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.