I'd probably do a check to make sure that last / is there, if it is, strip it off, then use [man]strrchr[/man]
function getnum($url) {
if(substr($url,-1) == "/") {
$url = substr($url,0,-1);
}
return substr(strrchr($url,"/"),1);
}
$url = "http://blah.com/blah/123/";
$id = getnum($url);
echo $id;