need the last part of the url
http://example.com then the last part is nothing if it is http://example.com/i then last part is i if it is http://example.com/i/am/file.php then last part is file.php
not sure if I use regex or what
You can also use the lastIndexOf() function to locate the last occurrence of the / character in your URL, then the substring() function to return the substring starting from that location: console. log(this. href.
Get Last URL Segment If you want to get last URI segment, use array_pop() function in PHP.
The current URL can be obtained by using the 'URL' property of the Document object which contains information about the current URL. The 'URL' property returns a string with the full location of the current page, along with containing the string having the HTTP protocol such as ( http://).
This is a simple example:
<?php
$url = "http://example.com/i/am/file.php";
$keys = parse_url($url); // parse the url
$path = explode("/", $keys['path']); // splitting the path
$last = end($path); // get the value of the last element
?>
I hope this help you ;)
There is a function called parse_url().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With