Hi all i am new in php
and i have some question how to do that.
I have URL like this
http://localhost/royale/?lang=am
And I need to take "am"
I search and find this
$_SERVER['QUERY_STRING']
but it return "lang=am"
Hi all i am new in php
and i have some question how to do that.
I have URL like this
http://localhost/royale/?lang=am
And I need to take "am"
I search and find this
$_SERVER['QUERY_STRING']
but it return "lang=am"
you can get the value as..
<?php
$lang = $_GET['lang'];
echo $lang;
?>
or if you are not sure about the value of parameter, then check it first by..
<?php
if(isset($_GET['lang'])){
$lang = $_GET['lang'];
echo $lang;
}
?>
If all you want is the value of "lang", $lang = $_GET['lang'];
// this is 'am'
how about:
// Check first if lang is on the URL query string
if (isset($_GET['lang'])) {
// If so, then do what you want with $_GET['lang']
$lang = $_GET['lang'];
echo $lang;
}
The parse_url with the parse_str function will take a URL string and create an associative array from the arguments
$parts = parse_url($url);
parse_str($parts['query'], $query);
echo $query['lang'];
Answer taken from here https://stackoverflow.com/a/11480852/3944304 (I tried linking to it before, but was told my answer was trivial)
I'm amazed that nobody has mentioned the article in the PHP docs about $_GET. This is what you are looking for, OP.