Php 用于将高级搜索字符串转换为assoc数组的包?

Php 用于将高级搜索字符串转换为assoc数组的包?,php,regex,search,term,Php,Regex,Search,Term,我想知道是否有人知道一个PHP软件包(或搜索google的正确术语)用于使用高级搜索词并将其转换为关联数组 例1: $term = 'blue birds country:england' 将转换为以下内容: [ 'country' => 'england' 'other' => 'blue blirds' ] [ 'country' => 'united kingdom', 'month' => 'January', 'oth

我想知道是否有人知道一个PHP软件包(或搜索google的正确术语)用于使用高级搜索词并将其转换为关联数组

例1:

$term = 'blue birds country:england'
将转换为以下内容:

[
    'country' => 'england'
    'other' => 'blue blirds'
]
[
    'country' => 'united kingdom',
    'month' => 'January',
    'other' => 'blue blirds'
]
例2:

$term = 'country:"united kingdom" blue birds month:January'
将转换为以下内容:

[
    'country' => 'england'
    'other' => 'blue blirds'
]
[
    'country' => 'united kingdom',
    'month' => 'January',
    'other' => 'blue blirds'
]
我曾尝试用preg_match来区分一组中的单个单词(例如
group:word
)和双引号中的多个单词(例如
group:word1 word2 word3
)。

使用
preg_match\u all()
将字符串拆分为多个组件

(\w*?):(“*?”\w*)|(\w+)
将其拆分为
名称:“值”/value
部分。然后,将它们组装回具有适当部分的输出(检查正则表达式的哪个部分匹配)

这给了。。。 排列


是否有一个术语的值中有空格?例如,其他=蓝红色的鸟xxxyyy@AliGhalambaz是的,在这种情况下,我希望这些词包含在双引号中。e、 g.国家:“联合王国”将变成['country'=>'united kingdom'],您可以使用正则表达式,如
[\w]+:([\w]+|“[\w\s]+”
来提取键值对。您最好使用正则表达式拆分字符串,该正则表达式可以检测不在引号内的空格,然后分别处理每个项目。为什么您总是编写
birds
,然后编写
blirds
?@Xatenev,因为我在键入时不够小心,对不起:-)。