如何从完整的URL中提取第一个URL段?应清理第一个URL段以替换-
空格.
完整的URL
http://www.domain.com/River-Island/River-Island-T-Shirt-with-Triangle-Girl-Print/Prod/pgeproduct.aspx?iid=2516020
Run Code Online (Sandbox Code Playgroud)
期望的Outpput
River Island
Run Code Online (Sandbox Code Playgroud)
Ten*_*eff 14
您可以使用:
$url = 'http://www.domain.com/River-Island/River-Island-T-Shirt-with-Triangle-Girl-Print/Prod/pgeproduct.aspx?iid=2516020';
$parsed = parse_url($url);
$path = $parsed['path'];
$path_parts = explode('/', $path);
$desired_output = $path_parts[1]; // 1, because the string begins with slash (/)
Run Code Online (Sandbox Code Playgroud)