【发布时间】:2012-01-06 13:34:12
【问题描述】:
我正在用 PHP 处理记录,想知道是否有一种有效的方法来提取类型:以下每个记录中的值。流派:可以是字符串中的任何位置。
在下面的字符串中我需要抽出单词“alternative”(最后一个单词)
[media:keywords] => upc:00602527365589,Records,mercury,artist:Neon
Trees,Alternative,trees,neon,genre:alternative
在下面的字符串中我需要拉出“Latin / Pop,latino,Pop”
[media:keywords] => genre:Latin / Pop,latino,Pop,upc:00602527341217,artist:Luis
Fonsi,luis,universal,Fonsi,Latin
在下面的记录中我需要抽出“其他”
[media:keywords] => upc:793018101530,andy,razor,Other,tie,genre:other,artist:Andy
McKee,McKee,&
在下面的记录中我需要拉出“rock,flotsam,jetsam”
[media:keywords] => and,upc:00602498572061,genre:rock,flotsam,jetsam,artist:Flotsam
And Jetsam,rock,geffen
我在这上面扯了我的头发(反正还剩下什么)。
【问题讨论】:
-
我不擅长使用正则表达式,但我做到了
(genre:).*(?=.*\:)是我能做的最大值。如果有人可以进化它..