preg_match条件块何时执行?
preg_match
块何时执行的条件?
我有一个
$A = Array (
[0] => KSO/OCMT/GBP66401,/ 001 VTS EMIS 43628
[1] => KSO/OCMT/GBP1836,22/ ENCT LCR 090724
)
$test = 'KSO';
foreach($A as $temp_indice=>$temp)
{
if(preg_match("`(.*)".$test."(.*)`im", $temp,$matches))
{
//WHEN THIS BLOCK IS EXECUTE?
}
}
我已阅读 preg_match
没有从上面的代码就可以理解了。
这里有人能很好地理解 preg_match
解释一下吗?
preg_match
condition when the block will execute?
I have an
$A = Array (
[0] => KSO/OCMT/GBP66401,/ 001 VTS EMIS 43628
[1] => KSO/OCMT/GBP1836,22/ ENCT LCR 090724
)
$test = 'KSO';
foreach($A as $temp_indice=>$temp)
{
if(preg_match("`(.*)".$test."(.*)`im", $temp,$matches))
{
//WHEN THIS BLOCK IS EXECUTE?
}
}
I have read preg_match
not get the understand from the above code.
Could anybody here good understand about preg_match
explain me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
preg_match() 是关于正则表达式(又名正则表达式)的,它的目标是搜索字符串是否与特定模式匹配,例如检查它是否包含特定单词,是否是电子邮件,邮政编码,...
这里是您的正则表达式将匹配任何包含字符串“KSO”的字符串。正则表达式使用特定的语法,这可能就是您不理解它是如何工作的原因。您可以在这里找到更多详细信息:http://www.regular-expressions.info/
preg_match() is about regular expressions (aka regex), its goal is to search if a string matches a specific pattern, for example check if it contains a specific word, if it's an email, a zip code, ...
Here your regex will match any string containing the string 'KSO'. Regex uses a specific syntax, that's probably why you don't understand how it works. You will find more details here : http://www.regular-expressions.info/
如果未找到匹配项,则
preg_match
返回0
;如果存在匹配项,则返回1
(并在此停止,使用preg_match_all
更多)0
也称为布尔值false
和1
代表true
。这意味着,如果找到匹配项(每次在名为
$A
的数组行中找到KSO
时),它将执行该块preg_match
returns0
if no match is found and1
if there's a match (and stop there, usepreg_match_all
for more)0
is also known as the booleanfalse
and1
fortrue
.That means, if a match is found (each time
KSO
found in a row of your array named$A
) it'll execute the block