-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,615
  • 3
  • 29
  • 42

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,268
  • 1
  • 11
  • 24
3

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

kylehyde215
  • 1,206
  • 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
  • 4,713
  • 8
  • 41
  • 76
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,475
  • 1
  • 13
  • 27
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
  • 1,912
  • 3
  • 17
  • 29