-2

Suppose the URL is https://www.example.com/page.php?id=1&title=this+is+a+sample+content.

Now my question is to retrieve the values of id and title here

jww
  • 97,681
  • 90
  • 411
  • 885
Ayush
  • 9
  • 5
  • For retrieving query params, use `$_GET`. See http://php.net/manual/en/reserved.variables.get.php . – Barun Oct 21 '18 at 04:14
  • Possible duplicate of [Get URL query string parameters](https://stackoverflow.com/q/8469767/608639), [How to get parameters from a URL string?](https://stackoverflow.com/q/11480763/608639), etc. – jww Oct 21 '18 at 06:07

2 Answers2

0

You can get the URL params with $_GET in PHP. You may also have a look at the $_GET documentation.

In your case it would be:

<?php

echo $_GET["title"];

Or the better variant with an if statement.

<?php

if(isset($_GET["title"])) {
  echo htmlspecialchars($_GET["title"]);
};
Christopher Dosin
  • 1,301
  • 9
  • 15
0

If you are on same page page.php, then you can get variable like this:

<?php

    $id    = $_GET['id'];

    $title = $_GET['title'];

?>

So, this will output is

id = 1

title = this is a sample content
Kirk Beard
  • 9,569
  • 12
  • 43
  • 47
Sanee
  • 1
  • 1