https://qiita.com/n0bisuke/items I want to extract the last part from the URL such as PHP
split.php
$url = "https://qiita.com/n0bisuke/items";
$tmp = explode("/", $url);
$end_word = end($tmp);
Python
split.py
url = "https://qiita.com/n0bisuke/items"
tmp = url.split('/')
end_word = tmp[-1]
In the case of Python, it may be a feature that PHP does not have that it can be counted from the end by specifying [-1]. If you specify [-2], you can get the second from the end.
Recommended Posts