since this is typically a function to be used on all pages in your website, I do not see the big difference in adding
<?php UsersOnline(); ?>
On the other hand, you can always create a droplet that captures the output of the snippet..
<?phpNote: the dropletcode above is not tested!
$users = ob_get_contents();