Answer the question
In order to leave comments, you need to log in
How to get the latest?
There is a url address with unlimited number of levels and how to always get the last level. Example page-2 / sub-page-2 / how to get from it - "sub-page-2", and if let's say there is sub-page-3, then display it?
Answer the question
In order to leave comments, you need to log in
echo basename($url), PHP_EOL;
// если адрес содержит get-параметры или якоря
echo basename(parse_url($url)['path']), PHP_EOL;
ideone.com/fMIXvtfunction get_last($url){
$result = explode('/', trim(parse_url($url, PHP_URL_PATH), '/'));
return end($result)
}
print get_last('страница-2/под-страница-2/'); // под-страница-2
$p=explode('?',$url);
$p=explode('/',$p[0]);
if($p[count($p)-1]!='') $p=$p[count($p)-1];
else $p=$p[count($p)-2];
echo $p;
If it's a crutch, then you can do this:
<?php
$url = "страница-2/под-страница-2/еще/еще-77-раз/";
$temp_result = explode("/", $url); // Array ( [0] => страница-2 [1] => под-страница-2 [2] => еще [3] => еще-77-раз [4] => )
$temp_result = array_diff($temp_result, array('')); // удаляем пустые элементы
echo end($temp_result); // выводим моследний элемент
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question