Jump to content

take out param from URL..


mkosmosports

Recommended Posts

Hello,

 

I have a 'page' parameter in the URL. I dont know whether it will be preceeded by a ? or a &, but I want to take it out and put the result into a variable.

 

Right now Im accomplishing that using simple regex and if/else statements. Im wondering if there is a ready-made php function which would know how to manipulate URL's like that.

 

Thanks.

mkosmosports

Link to comment
https://forums.phpfreaks.com/topic/91550-take-out-param-from-url/
Share on other sites

If you mean something like http://mysite.com/index.php?page=1

 

then just use $_GET

 

<?php
//Assume the url is http://mysite.com/index.php?page=1&name=jim

$page=$_GET['page'];
$name=$_GET['name'];
echo $name.' is on page '.$page;   //This will output  Jim is on page 1

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.