$str = "http://127.0.0.1/cartella/cartella1";
$str = substr( $str, 0, (strrpos($str, '/') + 1) );
echo $str;