PHP string Matching

Source: Internet
Author: User
There are two arrays, each of which is a

$template1 = array(            "您好,你的网址是@,请访问",            "您预约的时间在@,请按时到@报道",            "您的面试一结束,请给@评价吧,网址在@")$template2 = array(            "你的验证码是@",            "所有的特殊字符有@")

Where the @ is any possible string, now suppose I get a string

$message = "您好,你的网址是http://www.baidu.com/jsdkj,请访问";

To determine $message which array this belongs to, how to judge?

Reply content:

There are two arrays, each of which is a

$template1 = array(            "您好,你的网址是@,请访问",            "您预约的时间在@,请按时到@报道",            "您的面试一结束,请给@评价吧,网址在@")$template2 = array(            "你的验证码是@",            "所有的特殊字符有@")

Where the @ is any possible string, now suppose I get a string

$message = "您好,你的网址是http://www.baidu.com/jsdkj,请访问";

To determine $message which array this belongs to, how to judge?

Turn the string in the template into regular, and then match the message one by one.

Like what:

$template1 = array(            "您好,你的网址是.*,请访问",            "您预约的时间在.*,请按时到.*报道",            "您的面试一结束,请给.*评价吧,网址在.*")

It is important to note that if the template array is larger, performance may be affected. In addition, template rendering should usually be one-way, so I doubt the rationality of this requirement.

in_arraycan't you just take care of it? Is it that I misunderstood the landlord's meaning?

Strpos judgment in the form of a keyword.

This logic is too rare, usually based on the variable + template to get a message, and do not need you according to the message back ah, is it wrong to understand?

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