-2

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"

Aram Mkrtchyan
  • 2,690
  • 4
  • 31
  • 47

5 Answers5

4

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;
      }
 ?>
Sarath
  • 2,318
  • 1
  • 12
  • 24
3

If all you want is the value of "lang", $lang = $_GET['lang']; // this is 'am'

kylehyde215
  • 1,216
  • 1
  • 11
  • 18
3

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;
}
Vainglory07
  • 5,073
  • 10
  • 43
  • 77
2

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)

Community
  • 1
  • 1
CT14.IT
  • 1,635
  • 1
  • 15
  • 31
2

I'm amazed that nobody has mentioned the article in the PHP docs about $_GET. This is what you are looking for, OP.

$_GET @ PHP docs

Christian Lundahl
  • 2,000
  • 3
  • 18
  • 29