username in rewritten URL, howto use it in a template

I created a new function, with which i get the username. Is there any problem with using it? Or is there a cleaner way of doing it?

function getmyuser() {
$test = substr($_SERVER["REQUEST_URI"], strrpos($_SERVER["REQUEST_URI"],"/user/")+6);
return str_replace("https://wordpress.stackexchange.com/",'', $test);
}