如何在PHP中获取当前链接的子字符串?

I am having this PHP link :

http://localhost/OnlineShop/show_cat.php?catid=1

I want to be able to get the substring value of the link after the "=" and to visualize it on the same page. In this case is 1.

You want like this:

if(isset($_GET['catid'])){

      echo $_GET['catid']; 

}
explode("=", $sting)[1]

There are a lot of ways.

Use can simple use parse_url(), parse_str() For getting parameter value from url.

You can do somthing like this:

$url ="http://localhost/OnlineShop/show_cat.php?catid=1";
$parts = parse_url($url);
parse_str($parts['query'], $query);
echo $query['catid'];

DEMO

Want less code??? try simpler method as @Hanky웃Panky Suggest:

$url ="http://localhost/OnlineShop/show_cat.php?catid=1";
parse_str(parse_url($url,PHP_URL_QUERY), $query);
echo $query['catid'];

DEMO

This can also be a way:

$string = "http://localhost/OnlineShop/show_cat.php?catid=1";
$id = substr($string, strpos($string, '=') + 1);

If this is on your server, you can use $_GET superglobal (like the other answers have suggested)

if( array_key_exists('catid', $_GET) ) {
  echo $_GET['catid'];
}

But, if you want to evaluate the URL, without it being in the address bar; use parse_url and a mixture of string manipulators.

$arrUrl = parse_url('http://localhost/OnlineShop/show_cat.php?catid=1');

echo $intCatId = filter_var($arrUrl['query'], FILTER_SANITIZE_NUMBER_INT);

https://eval.in/186415

Documentation

You Can Print Variable Like This

if(isset($_GET['catid'])){ echo $_GET['catid']; }

OR

You can also use

$_REQUEST['catid']

For Access It.