這裏的URI路徑我需要解析:正則表達式爲URI路徑的第一3個部件
大鼓/ SAM /β-類森林%E2%84%A2 /產物的一個
我需要只提取前三個以斜線結尾的組件。
preg_match("/^([\w\/ %\.-]*){3}/", $input_line, $output_array);
這幾乎得到我想要的,但它不包括'%E2%84%A2'。我一直在重新排列http://www.phpliveregex.com/的東西,但無濟於事。
請注意,如果我嘗試解析完整的URL,說mysite.com/tom-tom/sam/beta-forest%E2%84%A2/product-a,那麼這個正則表達式得到我想要的:
的preg_match(「/^(https?://)?([\da-z.-]+).([az.]{2,6})([/\w %。 - ] *){3} //「,$ path,$ output_array);
我需要解析URI路徑,但我需要包含%符號。嘆氣..
編輯:
我的預期成果是:
tom-tom/sam/beta-forest%E2%84%A2/
什麼是你期望的輸出? – 2014-09-23 15:08:15
也許parse_url可能對你有用http://mx1.php.net/manual/es/function.parse-url.php – 2014-09-23 15:08:32
@Alx http://regex101.com/r/rD4sO4/2 – 2014-09-23 15:10:08