-1

Not like as we get id from URL using ?id=value and using $GET.

i have a URL like below:

https://localhost/booktheparty/index.php?/hyderabad/corporate-party-planner/view-corporate-entertainment-activities/ENT105012/50/12

i cant edit the url because the last parameters are coming from database.

i need to get the value "12" which is present at the very end of the URL. Is there any way to do it?

Mohsen Shakibafar
  • 254
  • 1
  • 2
  • 15

3 Answers3

1

You can use explode.

$url_exp =  explode("/", $url);
$lastValu = end($url_exp);
Bhavik
  • 495
  • 2
  • 10
0

In MySQL, you would use substring_index():

select substring_index(url, '/', -1) as last_part
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

You can use regular expression

$url='https://localhost/booktheparty/index.php?/hyderabad/corporate-party-planner/view-corporate-entertainment-activities/ENT105012/50/12';
preg_match("/\/(\d+)$/",$url,$matches);
$lastParams = $matches[1];

You can pass this variable in another page using query string for example

header('Location: http://www.ccm.net/forum/?var='.$lastParams);

and use $_GET['var'] on that page to get the value

Rakesh Jakhar
  • 6,380
  • 2
  • 11
  • 20
  • getting it, but no able to pass it to another page –  May 04 '19 at 12:26
  • @ZubairShah you can assign this value to any other variable and use that variable in the url to redirect OR you can use session – Rakesh Jakhar May 04 '19 at 12:26
  • how is that? can you please tell me so i can complete my work and accept your answer –  May 04 '19 at 12:30