如何从完整的URL中提取第一个URL段?应清理第一个URL段以用空格替换 – .
完整的URL
http://www.domain.com/River-Island/River-Island-T-Shirt-with-Triangle-Girl-Print/Prod/pgeproduct.aspx?iid=2516020
期望的Outpput
River Island
您可以使用:
原文链接:https://www.f2er.com/php/135176.html$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 (/)