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?