我正试图得到整句话:
PRICE CHANGE this this : this var1 : this/this (this) var2,var3 : 111,11 Price(€) : 1.021 start from : 2012-07-26 18:15:00
发件人:
timezone. PRICE CHANGE this : this var1 : this/this(this) var2, var3 : 119, 111 Price(€) : 5.021 start from : 2012-07-26 18:15:00 PRICE CHANGE this : this this2 var1 : this (this ) var2, var3 : 1604, 452 Price(€) : 6.014 start from : 2012-07-26 18:15:00 bla bla bla bla.
使用此:
body = "timezone. PRICE CHANGE this : this var1 : this/this(this) var2, var3 : 119, 111 Price(€) : 5.021 start from : 2012-07-26 18:15:00 PRICE CHANGE this : this this2 var1 : this (this ) var2, var3 : 1604, 452 Price(€) : 6.014 start from : 2012-07-26 18:15:00 bla bla bla bla."
$test = preg_match_all('/PRICE CHANGE's*(.*?)*('d+:'d+:'d+)', $body, $result);
它不起作用,救命?
preg_match_all('/PRICE CHANGE.*?(?=PRICE CHANGE)/', $body, $result);
会成功的,除非有什么你没有告诉我们的结构。如果它真的只是一个价格变化的列表,这将做tric,并且可读性更强。
如果你不知道,'(?='是一个前瞻性声明。它是一个零宽度(不匹配任何字符)断言,用于检查即将出现的字符。当与懒惰运算符结合使用时,它可能是分解字符串的好方法。
如果我理解正确,你想从每次更改中获得时间,对吗?要做到这一点,你可以这样改变你的表达方式:
'/PRICE CHANGE's*(.*?)('d+:'d+:'d+)/i'
也许i
修饰语不是完全必要的。