任何人都可以告訴我爲什麼這不起作用嗎?我只是想從URL獲得test.jpg放在用正則表達式獲取URL的一部分
$html = 'this/large/test.jpg)';
$str = $html;
preg_match('/\/large\/(\d+)\)/',$str, $matches);
echo $matches[1];
任何人都可以告訴我爲什麼這不起作用嗎?我只是想從URL獲得test.jpg放在用正則表達式獲取URL的一部分
$html = 'this/large/test.jpg)';
$str = $html;
preg_match('/\/large\/(\d+)\)/',$str, $matches);
echo $matches[1];
因爲\d
比賽小數(即[0-9]
)和test.jpg
不是。
嘗試preg_match('/\/large\/(.+)\)/',$str,$matches);
。
而不是正則表達式,使用[parse_url()](http://php.net/parse_url) – 2012-01-08 07:52:57
'this/large/test.jpg)'對於URL來說看起來有點不尋常。 '$ html'也是它的變量的一個奇怪的名字。這是真實的代碼嗎? – Johnsyweb 2012-01-08 07:55:05