-2
我正在使用我在this question上找到的答案以允许我拥有搜索运算符。匹配运算符:术语和运算符:用PHP搜索运算符的术语
它的一个问题是,它要求运算符和单词之间没有空格。
所以它会匹配operator:something
但不是operator: something
所以我想知道的是我如何匹配任何形式?
preg_match_all('/
(?:
([^: ]+) # command
: # trailing ":"
)
(
[^: ]+ # 1st word
(?:\s+[^: ]+\b(?!:))* # possible other words, starts with spaces, does not end with ":"
)
/x',
$search, $matches, PREG_SET_ORDER);
$result = array();
foreach($matches as $match) {
$result[$match[1]] = isset($result[$match[1]])
? $result[$match[1]] . ' ' . $match[2]
: $match[2];
}
你做什么由萨凡纳你所提供的代码更改只是问这个答案,而没有在这个工作 –
你必须发布输入字符串和期望的输出,而不是一个错误的书面帖子的链接。谢谢。 –