1

Here is example of URL from which I want to extract the last part which is name of the person.

 yourdomain.com/?n=PERSON . 

I want the part after

" ?n= " 

Then use this person name on the same HTML page. So I will be showing this person name on the web page. The web page is in HTML. DO I need java script or PHP code? Thanks

fantaghirocco
  • 4,761
  • 6
  • 38
  • 48

4 Answers4

0

The part after the domain, path and file is called Query String.

You can access the data within it by using php

in the html:

<?php echo $_GET['n']; ?>

This example uses your own example. domain.com/path/file.php?n=Jim_Williams

Dieter Kräutl
  • 657
  • 4
  • 8
0

You can use javascript for this purpose

var url_string = window.location.href; // www.test.com?n=Person
var url = new URL(url_string);
var paramValue = url.searchParams.get("n");
alert(paramValue);

Put this code under <script> tag and you can also run it in your .html file.

You can also use php code to get $_GET request. For this purpose you must have to make a file with .php extension and type code as below

<?php
 echo $_GET['n'];
?>
Zain Farooq
  • 2,956
  • 3
  • 20
  • 42
0

You can access URL parametrs in php by using 'GET' method.

By taking your example, you can do it by using

<?php
    $name = $_GET['n'];
?>

You can use $name anywhere on page where you want to display the name like below

<?php echo $name; ?> 
shubhangee
  • 529
  • 3
  • 10
0

Like this <?= $_GET['n'] ?> which's equivalent to <?php echo $_GET['n'] ?>

Robert
  • 19,800
  • 5
  • 55
  • 85