How can I extract the first url from a full url? The first segment of the URL must be cleared to replace with - space .
-
Full URL
http://www.domain.com/River-Island/River-Island-T-Shirt-with-Triangle-Girl-Print/Prod/pgeproduct.aspx?iid=2516020
Desired Performance
River Island
You can use:
$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 (/)
$page = explode('/', substr($_SERVER['REQUEST_URI'], 1), 2); echo str_replace("-"," ", $page[0]);
Try the following: /http:\/\/[^\/]+\/([^\/]+)/i
/http:\/\/[^\/]+\/([^\/]+)/i
See here: http://regex101.com/r/lB9jN7
$path = parse_url($url, PHP_URL_PATH); $first = substr($path, 0, strpos($path, '/'));
Check the docs for these three features. You may have to remove the slash from the beginning of the path, I'm not sure.
Do you have CodeIgniter ... ???, then it could be
$this->uri->segment(segment number of url);
and it needs to load uri library in Controller
Source: https://habr.com/ru/post/923423/More articles:Problems with MultipartFormDataStreamProvider - asp.net-mvcIs there a way to link a specific paragraph on a page without bindings? - htmlWhat returns in Ruby if the last expression evaluates is the statement If - functionJavascript find text on page - javascriptErlang fail-safe application: PA or CA CAP? - erlangShould a built-in function be defined before it is called? - optimizationImplementing Javascript Quick Search? - javascriptBuilt-in Functions / Methods - c ++Visual Studio Unit Assert.AreEqual authentication completes with identical expected and actual values - c #CSS page counter in print (or PDF) output - cssAll Articles