-5

I have a URL like http://localhost/m/2016/05/05/sebut-gubernur.

If link is clicked, I want get sebut-gubernur.

Biffen
  • 6,249
  • 6
  • 28
  • 36
indra
  • 3
  • 2

2 Answers2

0
echo substr($url, strrpos($url, '/') + 1);
Sinto
  • 3,915
  • 11
  • 36
  • 70
0

The $_SERVER variable helps your. and also explode function.

$part = explode("/", urldecode($_SERVER['REQUEST_URI']));

echo $part[(count($part) - 1)]; //sebut-gubernur

Note: You also need .htaccess code for this kind of url.

OR

If you have the link as a string and want to get sebut-gubernur then try:

$link = 'http://localhost/m/2016/05/05/sebut-gubernur';
$part = explode("/", urldecode($link));

echo $part[(count($part) - 1)]; //sebut-gubernur
Murad Hasan
  • 9,565
  • 2
  • 21
  • 42