<?php
$a = 'https://vk.com/none';
$b = 'https://vk.com/id123';
$c = 'https://vk.com/id123456?a=b';
$d = '@none';
$e = 'some text';
function getUserId($link)
{
if (preg_match('/vk.com\/(?<id>[\w\d]+)/ui', $link, $m) && !empty($m['id'])) return $m['id'];
if (preg_match('/(?<uid>@[\w\d]+)/ui', $link, $m) && !empty($m['uid'])) return $m['uid'];
return false;
}
var_dump(getUserId($a));
var_dump(getUserId($b));
var_dump(getUserId($c));
var_dump(getUserId($d));
var_dump(getUserId($e));
//string(4) "none"
//string(5) "id123"
//string(8) "id123456"
//string(5) "@none"
//bool(false)