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
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
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"]);
};
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