Php string matching

Source: Internet
Author: User
There are two arrays: {code ...} here, @ is any possible string. Now let me get a string {code ...} how can I determine the array in which the $ message belongs? There are two arrays:

$ Template1 = array ("Hello, your website is @, please visit", "your reservation time is @. please report on time ", "your interview is over. please give @ a comment. visit @") $ template2 = array ("your verification code is @", "all special characters include @")

@ Is any possible string. Now let me get a string

$ Message = "Hello, your website is http://www.baidu.com/jsdkj. please visit ";

Determine this$messageWhich array does it belong to? how can this problem be determined?

Reply content:

There are two arrays:

$ Template1 = array ("Hello, your website is @, please visit", "your reservation time is @. please report on time ", "your interview is over. please give @ a comment. visit @") $ template2 = array ("your verification code is @", "all special characters include @")

@ Is any possible string. Now let me get a string

$ Message = "Hello, your website is http://www.baidu.com/jsdkj. please visit ";

Determine this$messageWhich array does it belong to? how can this problem be determined?

Convert the string in the template into a regular expression and match the message one by one.

For example:

$ Template1 = array ("Hello, your website is. *, please visit "," your reservation time is in. *, please arrive on time. * report "," your interview is over. please give it. * comment. The url is in. *")

It is worth noting that if the template array is large, performance may be affected. In addition, template rendering is usually unidirectional, so I am skeptical about the rationality of this requirement.

Onein_arrayCan this be done? Is it because I have misunderstood the meaning of the landlord?

Just judge strpos in the form of a keyword.

This logic is too rare. Generally, the message is obtained based on the variable + template and does not need to be reversed based on the message. Is it wrong?

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.