I want to get the characters after the last / in an url like http://www.vimeo.com/1234567
How do I do with php?
You can use substr and strrchr:
$url = 'http://www.vimeo.com/1234567';
$str = substr(strrchr($url, '/'), 1);
echo $str; // Output: 1234567
Here's a beautiful dynamic function I wrote to remove last part of url or path.
/**
* remove the last directories
*
* @param $path the path
* @param $level number of directories to remove
*
* @return string
*/
private function removeLastDir($path, $level)
{
if(is_int($level) && $level > 0){
$path = preg_replace('#\/[^/]*$#', '', $path);
return $this->removeLastDir($path, (int) $level - 1);
}
return $path;
}