0

I trying to split my static URL and get its value in my SQL Query.

www.mydomain.com/directory/A/37/257/file.html

I want to put url values LIKE

$a="A";
$b=37;
$c=257;

Please help me to split the above mention url.

Thanks

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
M.S.Khan
  • 99
  • 1
  • 10
  • 1. Does your url always only have one directory, before you want to assign the values to the variables? 2. Have you tried something ? – Rizier123 May 17 '15 at 12:34
  • possible duplicate of [php how to split url](http://stackoverflow.com/questions/5257243/php-how-to-split-url) – Cwt May 17 '15 at 12:36

1 Answers1

3

Try:

$params = explode('/', $_SERVER['REQUEST_URI']);

$a = $params[2];
$b = $params[3];
//...

Note this will give you the parameters as strings. You can use intval() to convert any integer parameters.

thodic
  • 2,229
  • 1
  • 19
  • 35
  • 1
    you have 2 syntax errors. http://php.net/manual/en/reserved.variables.server.php and not closing the statement. As per the original answer http://stackoverflow.com/revisions/30286876/1 – Funk Forty Niner May 17 '15 at 12:31