[英]what is the preg_match solution in php for matching anything between '[' and ']'?
我有很多像这样的字符串
[anything]
这个词在哪里
anything == any kind of characters, such as ~!@#$%^&*()
用于匹配PHP中此类字符串的preg_match()
代码将是什么?
这应该可以满足您的需求:
<?php
$matches = array();
preg_match_all('/\[(.+?)\]/s', $string, $matches);
foreach ($matches[1] as $match) {
// Do stuff here.
}
在您的字符串中找到方括号之间的文本的所有时间都会循环遍历。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.