No need to over-complicate things here:
$url = 'www.shareit.me/matt';
$segs = explode('/', $url);
echo $segs[1]; // matt
Checking to see if it exists is as simple as if ( !empty($segs[1]) ) {}
Assuming you want the value matt
and not just the "path", this will work with all these:
www.shareit.me/matt // matt
www.shareit.me/matt/photos
www.shareit.me/matt/photos/vacation/nebraska/cows/ // matt
www.shareit.me/matt/photos?vacation=mexico&gallery=donkeyshow // matt
www.shareit.me/matt/loves/cheese // matt
If you actually want people to know that matt loves cheese, you should use parse_url() instead:
parse_url('www.shareit.me/matt/loves/cheese', PHP_URL_PATH); // /matt/loves/cheese