0

I have a link. Eg. abc.com/qwerty. I want to extract the part after / of every input just like examples below and use it just like a PHP GET input value and store it to a variable $page. Essentially, the link abc.com/qwerty should work like abc.com/proc.php?x=qwerty

Typed link        Part to be used as PHP GET input

abc.com/cvbx      cvbx
abc.com/ghvs      ghvx
abc.com/pabc      pabc

How can I do this?

2 Answers2

1

You can use: $_SERVER['REQUEST_URI']

$request_uri = $_SERVER['REQUEST_URI']; //returns '/cvbx'
$segments = array_filter(explode('/', $request_uri)); //array_filter to remove empty elements.
Ivanka Todorova
  • 9,964
  • 16
  • 66
  • 103
0

You can parse the url as described at http://php.net/manual/en/function.parse-url.php .

If you have urls as described there, you can get the path part with:

$input = substr(parse_url($url, PHP_URL_PATH),1);

substr is to remove the starting /

TopReseller
  • 623
  • 4
  • 6