2011-06-27 54 views
0

我想刮价的价格,即时通讯挣扎着写一些REG前抢特定文本REG-EX刮

<option value="1"> 
         1 


           (£&nbsp;70) 


        </option> 

价格相当多的显示像上面在源代码中有很多的空间。理想情况下,我想从字符串

这个虎视眈眈的70是我到目前为止

preg_match("/<option value=\"1\">(.+)<\/option>/siU", $html, $matches); 

我的一半预计今年抢1(£  70),但它没有工作,任何帮助?

+0

您需要阅读这个臭名昭着的SO问题的第一个答案:http://stackoverflow.com/questions/1732348/regex-match-o pen-tags-except-xhtml-self-contained-tags –

回答

0

那么,它does匹配。问题是(可能)的比赛中包含了一堆空白字符:

string(97) " 
         1 


           (£&nbsp;70) 


        " 

编辑
你可以做一个little sanitizing

$matches[1] = preg_replace('/\s+/s', ' ', trim($matches[1])); 

得出:

string(14) "1 (£&nbsp;70)" 
+0

这是一个答案或我的回答评论? :) – duedl0r

+0

@ duedl0r这是对这个问题的回答......好,有点。我试图证明正则表达式*确实匹配了某些东西,并且随后试图使结果与OP的期望值匹配。 – jensgram

+0

是的,现在我很清楚:) – duedl0r

0
/<option value=\"1\">(.*?\((.*?)\).*?<\/option>/ 

也确保你不换行(pattern modifiers

您可能还需要考虑使用XML解析器测试你的字符串。