preg_match_all("#4.*5#is","4xxx5xxx5",$re);
print_r($re);
output:
Array ( [0] => Array ( [0] => 4xxx5xxx5 ) ) 还有就是怎样能使第二种情况两个都匹配到。
---------------------------------------------
don't you think that will be a collision???
print_r($re);
output:
Array ( [0] => Array ( [0] => 4xxx5xxx5 ) ) 还有就是怎样能使第二种情况两个都匹配到。
---------------------------------------------
don't you think that will be a collision???
我主要是需要应用到这里:
网页源代码截取:
key <tr class="c"> <td ,...>asdasdasd <tr class="c"> <td ....>asdasdasd <tr class="c"> <td .....>asdasdasd
标记中间有若干空格和换行。
我需要匹配在key后的所有asdasdasd这里的内容,该怎么匹配?
#key<tr class="c">\s*<[^>]*>\s*(\S*)\s*<#isU这样只能匹配第一行asdasdasd,有什么办法?
#key.*<tr class="c">\s*<[^>]*>\s*(\S*)\s*<#isU
写错了,key后面的.*
试试:/<tr class="c">.*<td .*>(.*)</isU得到内容之后进行trim()来去除空格。
如果不定项呢?需要匹配所有4到5之间的项有没有可能?
TO zairwolfb(君子兰)
html里不只有这些项,一定要指定在key后面才行,否则会匹配到无关项。
那是没有可能的,除非你的项是固定的,
匹配进行完一次之后只会进行下一次匹配,
preg_match_all("#4.*5#is","4xxx5xxx5",$re);
这样会匹配整个字符串,因为使用了贪婪匹配,
贪婪是就是尽可能多的匹配!虽然4xxx5也符合,但没有4xxx5xxx5的串长,所以匹配了后者。
二者只能选一,不能同时匹配!
帮忙看看我上面那个匹配网页源代码的有没有办法?貌似也没办法了。
------------------------------I think the codes are incomplete and it is difficult to get the data you want.
这样的只能匹配最后一行。