-1

How to copy URL using PHP or JavaScript. I only want last part of URL like from this URL "https://stackoverflow.com/questions" i need "questions" only part to be shown in Text box

2 Answers2

1

parse_url() is your friend for PHP. See: http://php.net/manual/en/function.parse-url.php

Thomas Löffler
  • 5,922
  • 1
  • 14
  • 29
0

In Javascript you can get it by:

window.location.pathname

This shows the string /question if the URL is:

https://stackoverflow.com/questions

Here is an example of this site:

const URL = window.location.pathname;

console.log(URL);
Willem van der Veen
  • 33,665
  • 16
  • 190
  • 155