This question already has an answer here:
i need help with this code.
need get only last part of the current url with php.
example: http://www.site.com/index.php?user=username bla bla and the rest words
get all url after = character, i need only username bla bla and the rest words
for javascript: document.URL.split("=")[1];
i need for php please, thanks.
i have tried with this code but not works,
basename($_SERVER['REQUEST_URI']);
</div>
You can use explode("=",$url) -- this will return you an array with the string split with "="
you can use $_GET['user']
Use $_SERVER['QUERY_STRING']
to get the query string and then use explode to extract data after =
.
For eg: Using url http://www.site.com/index.php?user=username
<?php
$text = explode("=", $_SERVER['QUERY_STRING']);
print_r($text);
?>
Output:
Array
(
[0] => "http://www.site.com/index.php?user"
[1] => "username"
)
it seems you want the Value Passed through GET method you can simply get its value like this
<?php
if (isset($_GET['user']))
$a=$_GET['user'];
?>
Note: Use this only if you are sure that after ?' and before
=` the variable is user else you can also use
<?php
if (!empty($_GET)) {
$a=explode("=",$_SERVER["QUERY_STRING"]);
echo $a[1];}
else
echo 'Please provide username';
?>
?>
$current_url = $_SERVER["QUERY_STRING"];
$a=explode("=",$current_url);
echo $a[1];
//OR for CI framework
$current_url = current_url();
$a=explode("=",$current_url);
echo $a[1];