我想從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