0

I need help on php. I get full link with this code

$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

My link output is: http://localhost/Mid/photo-gallery/photos.php?ref=3%20%20ID=3 How can i get "3" ? I need last number. This number can be 3 digits. So maybe can be 444.

cimicimi
  • 208
  • 1
  • 2
  • 11

2 Answers2

1

you can do it by using the following code.It will work for you.

  $url = " http://localhost/Mid/photo-gallery/photos.php?ref=3%20%20ID=3 ";
  $urls = explode("ID=",$url);  
  echo $urls[1];    
stackers
  • 385
  • 4
  • 18
0

You can try something like that:

$idVal = substr(strrchr($url, "="), 1);

It will return everything after the last equal. You have to be sure that ID will always be your last get parameter in your URL though.

Matthieu
  • 948
  • 8
  • 8