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
            Asked
            
        
        
            Active
            
        
            Viewed 57 times
        
    -1
            
            
        - 
                    1Possible duplicate of [Get the full URL in PHP](https://stackoverflow.com/questions/6768793/get-the-full-url-in-php) – Obsidian Age Aug 08 '18 at 20:19
- 
                    1I think you should choose PHP or javascript and not ask on both languages. Also what do you mean by "shown in Text box" ? – Gabriel Devillers Aug 08 '18 at 20:19
- 
                    I want it in PHP and want show output in textarea – Sartaj Bloch Aug 08 '18 at 20:26
- 
                    You just have to get a hold on the QueryString or URL that comes in, then its a matter of parsing that string... that could be achieved in both language easilly. – Minus Aug 08 '18 at 20:36
2 Answers
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
- 
                    will you plz tell me how can i get output of it? can i store it in variable? – Sartaj Bloch Aug 08 '18 at 20:29
- 
                    
- 
                    You can store it in a variable using (const, var, let). Then you can access this variable later again and use it in a different location. Like in the console.log example. – Willem van der Veen Aug 08 '18 at 20:35
- 
                    ok, thank you but i am new i do not know how to do that that's why wrote here for help. – Sartaj Bloch Aug 08 '18 at 20:56
