URL1 : http://informatux.com/astuces/php RESULTAT : php
URL2 : http://informatux.com/astuces/php.php RESULTAT : php.php
URL3 : http://informatux.com/astuces/php.php?id=php&g=go RESULTAT : php.php
PHP | |
1 2 3 4 5 | <?php function getLastPartOfUrl($url) { return basename(parse_url($url, PHP_URL_PATH)); } ?> |
JS | |
1 2 3 4 5 6 7 8 9 10 | function getLastPartOfUrl($url) { var url = $url; var urlsplit = url.split("/"); var lastpart = urlsplit[urlsplit.length-1]; if(lastpart==='') { lastpart = urlsplit[urlsplit.length-2]; } return lastpart; } |
TAGs : Get Last Part Of Url By PHP / JS