我想从html源代码使用以下正则表达式的图像网址,但它失败时,图像的网址中有空格。例如,这个网址:preg_match_all正则表达式失败时,有空格
<img src="http://a57.foxnews.com/global.fncstatic.com/static/managed/img/Entertainment/876/493/kazantsev pink bikini reuters.jpg?ve=1&tl=1" alt="kazantsev pink bikini reuters.jpg" itemprop="image">
$image_regex_src_url = '/<img[^>]*'.'src=[\"|\'](.*)[\"|\']/Ui';
preg_match_all($image_regex_src_url, $string, $out, PREG_PATTERN_ORDER);
这让我回到以下。
http://a57.foxnews.com/global.fncstatic.com/static/managed/img/Entertainment/876/493/kazantsev
有没有办法匹配任何字符,包括空格?或者是我必须在php配置中设置的东西?
'。*'也包含空格。问题不在这里,正则表达式工作正常。显示您正在尝试应用的文字。这可能会发生,没有空格,但'''或'''(他们不应该在URL中) – Cheery 2014-10-12 00:18:11
你可以简化你的正则表达式:'
2014-10-12 00:31:56
I'm trying to post the string here to see if there's some other reason it won't work, but I'm having trouble with stackoverflow truncating it, is there a tag I can put in the comments when pasting in code? – techdog 2014-10-12 00:50:18